Rounded corner of list item on Android?

2019-04-16 11:33发布

How to setup the attribute to achieve the rounded corner for each item in the ListView? Please kindly give an example if you can, thanks!

for example: http://www.flickr.com/photos/jaxxdotorg/3640222441/in/set-72157619952823330/

EDIT: That's my code here for the answer.

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
    android:startColor="#ffff"
    android:endColor="#fddd"
    android:angle="270" />
<corners
    android:radius="13dp" />
<stroke
    android:width="1dp"
    android:color="#feee" />
</shape>

1条回答
虎瘦雄心在
2楼-- · 2019-04-16 11:51

You can achieve this with shapes.

Checkout the Shape Drawable documentation

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android">
    <corners
        android:radius="12dp"/>
    <stroke
        android:width="1dp"
        android:color="@color/blue" />
</shape>

The corner element specifies the size of the rounded corner. Now all you need to do is specify this drawable as the background to each list element.

查看更多
登录 后发表回答