ImageView with only bottom or top corners rounded(ImageView 只有底角或顶角是圆角的)
问题描述
我有这个问题的答案,但我花了太多时间寻找它.这就是我创建这个问题的原因,这样对其他人来说会更容易.
您不能像通常的 View 那样只用形状 @drawable 将图像的角弄圆.这就是为什么您需要在代码中对 Image 进行一些更改.
这是使用 Material Design 的另一种方法
就是快乐编码:).
I have answer on this question, but I spend too much time while searching for it. That's why I created this question, so it would be easier for others.
You can't just round image corners with shape @drawable like usual View. That's why you need to make some changes to Image inside code.
Here is the another way to do this using Material Design ShapeableImageView
Create one theme for shape and cornerFamily
<style name="ImageView.Corner" parent="">
<item name="cornerSizeTopRight">8dp</item>
<item name="cornerSizeTopLeft">8dp</item>
<item name="cornerSizeBottomLeft">0dp</item>
<item name="cornerSizeBottomRight">0dp</item>
<item name="cornerFamily">rounded</item>
</style>
Now add ShapeableImageView in XML:
<com.google.android.material.imageview.ShapeableImageView
android:layout_width="75dp"
android:layout_height="75dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/temp_product_image"
app:shapeAppearanceOverlay="@style/ImageView.Corner"/>
I you want to full rounded ShapeableImageView:
<style name="ImageView.Round" parent="">
<item name="cornerSize">50%</item>
</style>
Full Rounded Output:
That's it Happy Coding :).
这篇关于ImageView 只有底角或顶角是圆角的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ImageView 只有底角或顶角是圆角的


- Android - 拆分 Drawable 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01