[英]background image not showing of Card View
I try to create a little round view in relative layout.我尝试在相对布局中创建一个小圆形视图。 but when i set image(.jpg) in card view then image is not showing.但是当我在卡片视图中设置图像(.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>
I assume you want to create a round view that contains imageview.我假设您要创建一个包含 imageview 的圆形视图。 So first, set your image using ImageView and not the CardView itself.因此,首先,使用 ImageView 而不是 CardView 本身设置您的图像。
<androidx.cardview.widget.CardView
android:id="@+id/View"
android:layout_width="25dp"
android:layout_height="25dp"
app:cardCornerRadius="12.5dp"
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>
Normally, your imageview image would overlap your cardview, so to avoid that, just set your imageview clipToOutline to true programmatically in your activity.通常,您的 imageview 图像会与您的卡片视图重叠,因此为避免这种情况,只需在您的活动中以编程方式将 imageview clipToOutline设置为 true。
imageView.clipToOutline = true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.