【发布时间】:2012-11-20 06:02:34
【问题描述】:
我正在尝试创建一个圆形和白色的 ListView:
到目前为止,我已经尝试过使用属性来设置listview的背景,但是无法得到这个效果。如果有人能给我一些建议,那就太好了。
我知道我必须使用自定义列表视图,因此我有信心必须在 XML 中为自定义列表项重新创建它。
【问题讨论】:
标签: android xml android-listview
我正在尝试创建一个圆形和白色的 ListView:
到目前为止,我已经尝试过使用属性来设置listview的背景,但是无法得到这个效果。如果有人能给我一些建议,那就太好了。
我知道我必须使用自定义列表视图,因此我有信心必须在 XML 中为自定义列表项重新创建它。
【问题讨论】:
标签: android xml android-listview
您可以通过添加以下代码来创建它:
在可绘制文件夹中创建 rounded_corners.xml,如下所示:
rounded_corners.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="color of your choice" android:endColor="color of your choice"
android:angle="270"/>
<corners android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp" android:topRightRadius="10dp"/>
</shape>
并像这样将其添加到列表视图中:
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:background="@drawable/rounded_corners"
>
</ListView>
【讨论】: