Imageview with rounded corner using kotlin
10,322
Create res/drawable/round_outline.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp" />
</shape>
Set the drawable as your ImageView's background
android:background="@drawable/round_outline"
On ImageView (layout)
android:clipToOutline="true"
Related videos on Youtube
![VigneshK](https://i.stack.imgur.com/X8K7F.jpg?s=256&g=1)
Author by
VigneshK
Updated on June 04, 2022Comments
-
VigneshK about 2 years
I have created the layout with Imageview and I have set custom background with corner radius, the parent layout is cornered but the Imageview is not rounded cornered. How can I achieve this?
Thanks in advance.
bg.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="@color/list_item_bg"/> <stroke android:width="2dp" android:color="@color/colorAccent" /> <corners android:topLeftRadius="20dp" android:topRightRadius="20dp"/> </shape>
list_item.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/list_item_bg" > <ImageView android:id="@+id/food_image" android:layout_width="match_parent" android:layout_height="150dp" android:layout_marginRight="5dp" android:layout_marginLeft="5dp" android:layout_marginTop="2dp" android:scaleType="centerCrop" android:clipToOutline="true" android:background="@drawable/image_bg" android:src="@drawable/sample_image"/> </LinearLayout>
-
Molly over 5 yearsshare your layout code.
-
Kevin Kurien over 5 yearsthis should help link
-
-
VigneshK over 5 yearsI have tried the above code but I got the same issue
-
Anees over 5 yearsplease provider the xml layout file
-
VigneshK over 5 yearsI have added the code in my question.
-
Clean Coder almost 3 yearsclipToOutline is not found for imageview tag. So i followed this library: implementation 'com.makeramen:roundedimageview:2.3.0' . It works both with Java and Kotlin. Just replace your imageview with : <com.makeramen.roundedimageview.RoundedImageView android:layout_width="113dp" android:layout_height="113dp" ...etc.