How to add rounded corner as a background of Recyclerview in Android
Asked Answered
P

2

11

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.

Piemonte answered 3/3, 2016 at 21:22 Comment(1)
Take a look at this... #28713731Potpie
L
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"
Lactary answered 3/3, 2016 at 21:33 Comment(6)
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?Piemonte
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.Lactary
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.Piemonte
@Piemonte You will have to add the border to the item layout of the Recycler view and not the RecylerView itself.Moody
this does notwork when I set background color to recyclerview items!Dicks
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 cutBrueghel
T
0

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

Tufa answered 18/7, 2022 at 15:15 Comment(1)
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.Windfall

© 2022 - 2024 — McMap. All rights reserved.