我尝试在相对布局中创建一个小圆形视图。但是,当我在卡片视图中设置image(.jpg)时,图像未显示。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<androidx.cardview.widget.CardView
android:id="@+id/View"
android:layout_width="25dp"
android:layout_height="25dp"
android:background="@drawable/background"
app:cardCornerRadius="20dp"
android:layout_margin="2dp"
android:elevation="2dp"
android:layout_centerInParent="true">
</androidx.cardview.widget.CardView>
</RelativeLayout>
尝试一下。
<androidx.cardview.widget.CardView
android:id="@+id/View"
android:layout_width="25dp"
android:layout_height="25dp"
app:cardCornerRadius="20dp"
android:layout_margin="2dp"
android:elevation="2dp"
android:layout_centerInParent="true">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/background"/>
</androidx.cardview.widget.CardView>
并且在您的代码中,将imageview clipToOutline设置为true
imageView.clipToOutline = true