我正在 android java Eclipse 中开发一个应用程序,它有两个并排的列表视图,我想为每个添加边框list-view
。怎么办?请帮我...
问问题
4761 次
2 回答
5
您可以使用 shape 为每个列表视图设置背景边框。下面是示例 shape.xml 文件,您可以创建并将其设置为列表视图的背景。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#f3f3f3"/>
<stroke android:width="1dp" android:color="#bfbfbf"/>
<padding android:left="0dp" android:top="0dp"
android:right="0dp" android:bottom="0dp" />
</shape>
如果您的列表需要圆角,您可以使用
<corners android:radius="8dp" />
即使您可以通过 xml 文件设置背景,如下所示:
android:background="@drawable/shape"
并通过如下代码:::
listview_instance.setBackgroundResource(R.drawable.shape);
还要确保项目的 res/drawable 文件夹包含 shape.xml 文件。
于 2012-04-15T05:23:29.220 回答
1
一旦尝试这个在两个列表视图之间有分隔符
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="schemas.android.com/apk/res/android"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android1:layout_width="wrap_content"
android:layout_height="fill_parent"
android1:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="433dp"
android1:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="30dp" >
<ListView
android:id="@+id/listView1"
android:layout_width="229dp"
android:layout_height="wrap_content"
android:layout_marginRight="34dp"
android:layout_weight="0.37" >
</ListView>
<TextView android:id="@+id/tv"
android:layout_width="1dp"
android:background="#FF0000"
android:layout_height="wrap_content"/>
<ListView
android:id="@+id/listView2"
android:layout_width="667dp"
android:layout_height="wrap_content"
android:layout_weight="0.12" >
</ListView>
</LinearLayout>
</LinearLayout>
于 2012-04-15T12:35:27.397 回答