本文介绍了仅将底角或顶角弄圆的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!