CardView(
android.support.v7.cardview)保持白色,即使我通过android设置一个backround drawable:backround – 该文档给我的感觉,它应该工作.没有想法我在这里做错什么
解决方法
我知道这是一个古老的问题,但我有一个简单的解决方案 – 只要让CardView的第一个孩子成为
ImageView,并指定比例类型以适应XY.您可以通过将cardElevation和cardMaxElevation设置为0dp来摆脱额外的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"
android:layout_width="match_parent"
android:layout_height="200dp"
app:cardCornerRadius="4dp"
app:cardElevation="0dp"
app:cardMaxElevation="0dp">
<ImageView
android:src="@drawable/your_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"/>
<... your layout
.../>
</android.support.v7.widget.CardView>