penghaitao
penghaitao

Reputation: 256

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

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.

Upvotes: 11

Views: 21309

Answers (2)

durkester
durkester

Reputation: 21

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

Upvotes: 0

yUdoDis
yUdoDis

Reputation: 1098

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"

Upvotes: 18

Related Questions