如何在 Android 中创建带圆角的 ListView? [英] How do I create a ListView with rounded corners in Android?
问题描述
如何在 Android 中创建带圆角的 ListView?
How do I create a ListView with rounded corners in Android?
推荐答案
这是一种方法(感谢 Android 文档!):
Here is one way of doing it (Thanks to Android Documentation though!):
将以下内容添加到文件中(比如customshape.xml),然后将其放入(res/drawable/customshape.xml)
Add the following into a file (say customshape.xml) and then place it in (res/drawable/customshape.xml)
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#SomeGradientBeginColor"
android:endColor="#SomeGradientEndColor"
android:angle="270"/>
<corners
android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
完成此文件的创建后,只需通过以下方式之一设置背景:
Once you are done with creating this file, just set the background in one of the following ways:
通过代码:listView.setBackgroundResource(R.drawable.customshape);
通过 XML,只需将以下属性添加到容器(例如:LinearLayout 或任何字段):
Through XML, just add the following attribute to the container (ex: LinearLayout or to any fields):
android:background="@drawable/customshape"
希望有人觉得它有用...
Hope someone finds it useful...
这篇关于如何在 Android 中创建带圆角的 ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!