在 CardView 中使用图像作为背景(前棒棒糖设备问题)

在 CardView 中使用“图像/颜色”作为背景时,边缘可能会出现轻微的白色填充(如果默认卡片颜色为白色)。这是由于卡片视图中的默认圆角造成的。以下是如何避免 Pre-lollipop 设备中的边距。

我们需要在 CardView 中使用属性 card_view:cardPreventCornerOverlap="false"。1)。在 XML 中使用以下代码段。

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    card_view:cardPreventCornerOverlap="false"
    android:layout_height="wrap_content"> 
      <ImageView
            android:id="@+id/row_wallet_redeem_img"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            android:src="@drawable/bg_image" />

</android.support.v7.widget.CardView>
  1. 像 Java 这样的 cardView.setPreventCornerOverlap(false)

这样做可以消除卡边缘上不需要的填充。以下是与此实现相关的一些可视示例。

1 张 API 中带有图像背景的卡片 (非常好) StackOverflow 文档

2 带有图像背景的卡在 API 19 中没有属性 (注意图像周围的填充) StackOverflow 文档

3 带有图像背景的固定卡,带有属性 cardView.setPreventCornerOverlap(false)API 19 (现已修复) StackOverflow 文档

也了解这对文档这里
原来 SOF 后这里