10

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.

This is the screenshot of translate.

penghaitao
  • 226
  • 1
  • 3
  • 11
  • 1
    Take a look at this... http://stackoverflow.com/questions/28713231/recyclerview-item-separator – JpCrow Mar 03 '16 at 21:26

2 Answers2

18

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"
yUdoDis
  • 1,098
  • 6
  • 15
  • 2
    Thanks 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? – penghaitao Mar 03 '16 at 21:53
  • im 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. – yUdoDis Mar 03 '16 at 21:56
  • 2
    Yes, 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. – penghaitao Mar 03 '16 at 22:04
  • 2
    @penghaitao You will have to add the border to the item layout of the Recycler view and not the RecylerView itself. – Themasterhimself Jan 03 '17 at 17:27
  • this does notwork when I set background color to recyclerview items! – Hadi Apr 07 '20 at 09:04
  • if 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 – joghm Jul 15 '21 at 22:16
0

Put the recyclerview in a cardview, and set the cardview's corner radius.

durkester
  • 21
  • 4
  • 4
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 20 '22 at 12:01