小编典典

如何在 Android 中创建带圆角的 ListView?

all

如何在 Android 中创建带圆角的 ListView?


阅读 169

收藏
2022-08-08

共1个答案

小编典典

这是一种方法(感谢 Android 文档!):

将以下内容添加到文件中(例如 customshape.xml),然后将其放入(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>

完成创建此文件后,只需通过以下方式之一设置背景:

通过代码: listView.setBackgroundResource(R.drawable.customshape);

通过 XML ,只需将以下属性添加到容器(例如:LinearLayout 或任何字段):

android:background="@drawable/customshape"

希望有人觉得它有用…

2022-08-08