android - ImageView 只有底角或顶角是圆角的

标签 android imageview drawable shapes rounded-corners

我有这个问题的答案,但是我在寻找它时花了太多时间。
这就是我创建这个问题的原因,这样对其他人来说会更容易。
您不能像通常的 View 那样使用形状 @drawable 将图像的角弄圆。
这就是为什么您需要在代码中对 Image 进行一些更改。

最佳答案

这是使用 Material Design 的另一种方法ShapeableImageView
为形状和 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>
现在在 XML 中添加 ShapeableImageView:
<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"/>
我想要完整的 ShapeableImageView:
<style name="ImageView.Round" parent="">
  <item name="cornerSize">50%</item>
</style>
全圆输出:
enter image description here
就是这样快乐编码:)。

关于android - ImageView 只有底角或顶角是圆角的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66138001/

相关文章:

android - Shape XML Drawable无法解析成Bitmap XML Drawable

android - NestedScrolling 在 BottomSheetDialog 内的 Viewpager 内

android - 无法在 XML .Android 工作室中更改按钮的背景颜色

android - ImageView 适合宽度裁剪​​底部

android - 如何删除 ImageView 以使其不再存在?

安卓图片查看器

android - 在android中创建一个进度条,在进度条和反向进度条中改变它的颜色

android - 具有可绘制值的字符串数组到 int 数组

android - 谷歌钱包应用内支付不适用于 phonegap 框架

java - Java+Kotlin Android 项目中 Kotlin 文件中 Unresolved 引用错误