How to add rounded corner as a background of Recyclerview in Android
16,677
use this xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/color_white"/>
<stroke android:width="3dp"
android:color="@color/grey_ask"
/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"
/>
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
increase the *Radius values for more roundness. add this as backgound to your recylerview
android:background="@drawable/nameofxml"
Author by
penghaitao
Updated on July 18, 2022Comments
-
penghaitao almost 2 years
I have a list. And I want to add a background like round corner to it. So the list is like a big card view. How can I implement this just like Google Translate.
The rounded background can scroll as the listview does. So The shape.xml solution does not works here.
-
JpCrow about 8 yearsTake a look at this... stackoverflow.com/questions/28713231/…
-
-
penghaitao about 8 yearsThanks for your answer. I know this solution can add a background to the listview. But the background is static. I want the background can scroll as the listview does. So do you have some other ideas?
-
yUdoDis about 8 yearsim not sure i understand what you mean, this background will give your listview(container) rounded corners..isnt that the initial requirement? this is a shape drawable.
-
penghaitao about 8 yearsYes, but when I scroll this listview, I want the background move as the listview does. It is like a card. But this solution this background just stand there and listview just scroll inside. If you use the translate app, you may understand what I mean. My English is not good, please forgive me. And Thanks for your help.
-
Themasterhimself over 7 years@penghaitao You will have to add the border to the item layout of the Recycler view and not the RecylerView itself.
-
Hadi about 4 yearsthis does notwork when I set background color to recyclerview items!
-
joghm almost 3 yearsif i make the corners radius as big as 80dp for example, the items will scroll and fade on top of the transparent corners, is there a trick how to make items fade below the background drawable, like if the recyclerview is actually have its corners cut