[英]How can I create a list view with borders in Android?
I use a multi-column list-view to display data as like a grid, but I want a list-view with user-defined columns and rows with borders. 我使用多列列表视图来像网格一样显示数据,但是我想要一个带有用户定义的列和带有边框的行的列表视图。 Suggestions? 有什么建议吗?
main.xml main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
main1.xml main1.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/cust"
android:layout_width="70dp"
android:layout_height="70dp"
android:text="customer" />
<TextView
android:id="@+id/order"
android:layout_width="70dp"
android:layout_height="70dp"
android:text="order" />
<TextView
android:id="@+id/freight"
android:layout_width="70dp"
android:layout_height="70dp"
android:text="freight" />
<TextView
android:id="@+id/station"
android:layout_width="70dp"
android:layout_height="70dp"
android:text="station" />
</LinearLayout>
Method one : 方法一:
1) implement a custom adapter 1)实现自定义适配器
2) in the getview()
method, set a background (with border ) to the view before returning it. 2)在getview()
方法中,为视图设置背景(带有border ),然后再返回。
Method two: 方法二:
use ArrayAdapter
使用ArrayAdapter
1) make an xml file which cointains a TextView
with a background(which has a border ) 1)制作一个XML文件,该文件包含一个带有背景(带有边框 )的TextView
2) pass the reference to this xml to the ArrayAdapter
2)将对此xml的引用传递给ArrayAdapter
Here's a tutorial , in case you don't know what i'm talking about. 如果您不了解我在说什么,这是一个教程 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.