Reputation: 63
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.
<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>
What i want you can see in following image.
Upvotes: 0
Views: 1837
Reputation: 1464
I assume you want to create a round view that contains imageview. So first, set your image using ImageView and not the CardView itself.
<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.clipToOutline = true
Upvotes: 3