我正在尝试使用CardView,所有内部视图都在CardView的圆角内环绕。 但是我在cardview中的ImageView不像cardview那样得到圆角。
我的XML代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_margin="5dp"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.cardview.widget.CardView
android:clipToPadding="true"
app:cardBackgroundColor="@color/black"
app:cardCornerRadius="15dp"
android:layout_width="120dp"
android:layout_height="100dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:scaleType="centerCrop"
android:src="@drawable/post_placeholder"
android:id="@+id/customProfileGridImg"
android:layout_width="match_parent"
android:layout_height="50dp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
从上面的代码输出屏幕。
使imageview的高度和宽度与cardview相同它将工作
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_margin="5dp"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.cardview.widget.CardView
android:clipToPadding="true"
app:cardBackgroundColor="@color/black"
app:cardCornerRadius="15dp"
android:layout_width="120dp"
android:layout_height="100dp">
<ImageView
android:scaleType="centerCrop"
android:src="@drawable/post_placeholder"
android:id="@+id/customProfileGridImg"
android:layout_width="120dp"
android:layout_height="100dp" />
</androidx.cardview.widget.CardView>
</RelativeLayout>
尝试删除线性布局