在 Android ListView 加入外边框
时间: 2024-01-24 21:08:10 浏览: 107
你可以在 ListView 的布局文件中,给它的父布局添加一个边框来实现外边框的效果。具体的做法如下:
1. 在布局文件中,给 ListView 的父布局添加一个边框,比如可以使用 shape 标签来定义一个矩形的边框,代码如下:
```
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/white" />
<stroke
android:width="1dp"
android:color="@android:color/black" />
</shape>
```
这个代码定义了一个白色的实心背景,以及一个黑色宽度为 1dp 的边框。
2. 在 ListView 的父布局中添加背景属性,将这个边框作为背景,代码如下:
```
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/listview_border">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
```
这样,ListView 的外边框就添加完成了。
阅读全文
相关推荐














