ImageView 只有底角或顶角是圆角的 [英] ImageView with only bottom or top corners rounded

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆