如何删除 cardview 背景 android

How to remove cardview background android

我有一个包含图像视图的卡片视图,如屏幕截图所示:

由于图像是圆形的,我想删除 cardview 的背景,这样白色方块就不会显示了。

这是我的代码:

  <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:card_view="http://schemas.android.com/tools"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        card_view:cardCornerRadius="5dp"
        card_view:cardPreventCornerOverlap="true"
        android:paddingLeft="2.5dp"
        android:paddingRight="2.5dp">

        <android.support.v7.widget.AppCompatImageView
            android:id="@+id/caracteristica_imagen"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:adjustViewBounds="true"
            android:background="@android:color/transparent"
            android:cropToPadding="true"
            android:elevation="0dp"
            android:scaleType="fitStart"
            android:paddingLeft="2.5dp"
            android:paddingRight="2.5dp" />
    </android.support.v7.widget.CardView>
app:cardBackgroundColor="@android:color/transparent"

添加这个

在XML

中使用

在XML中添加xmlns:card_view="http://schemas.android.com/apk/res-auto"

然后

card_view:cardBackgroundColor="@android:color/transparent"

或 Java

cardView.setCardBackgroundColor(Color.TRANSPARENT);