下面是我的表格代码.我的屏幕看起来像这个
http://imgur.com/dFP298o,但我想让它看起来像这样
http://imgur.com/YuYJiJx.如何添加边框围绕每一行和表格布局?
<TableLayout android:id="@+id/table2" android:layout_width="fill_parent" android:layout_below="@+id/test_button_text23" android:layout_marginLeft="45dp" android:layout_marginBottom="25dp" android:layout_marginRight="45dp" android:layout_height="fill_parent" android:stretchColumns="*" > <TableRow android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:gravity="left" android:text="Quantity" android:textStyle="bold" /> <TextView android:gravity="center" android:textStyle="bold" android:text="Item" /> </TableRow> </TableLayout>
<?xml version="1.0" encoding="utf-8"?> <TableRow xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/localTime" android:textColor="#000000" android:gravity="left" /> <TextView android:id="@+id/apprentTemp" android:textColor="#000000" android:gravity="center" /> </TableRow>
View row = getLayoutInflater().inflate(R.layout.rows,null); ((TextView) row.findViewById(R.id.localTime)).setText(item.getString("Item")); ((TextView) row.findViewById(R.id.apprentTemp)).setText(item.getString("Quantity"));
解决方法
为了在表格行周围和表格布局周围创建边框,您需要创建一个drawable作为边框,然后将其设置为行的背景.
例如:
RES /抽拉/ border.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape= "rectangle"> <solid android:color="#000000"/> <stroke android:width="1dp" android:color="#000000"/> </shape>
RES /布局/ your_layout.xml
<TableLayout android:id="@+id/table2" android:layout_width="fill_parent" android:layout_below="@+id/test_button_text23" android:layout_marginLeft="45dp" android:layout_marginBottom="25dp" android:layout_marginRight="45dp" android:layout_height="fill_parent" android:stretchColumns="*"> <TableRow android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/border"> <TextView android:gravity="left" android:text="Quantity" android:background="@drawable/border" android:textStyle="bold"/> <TextView android:gravity="center" android:textStyle="bold" android:background="@drawable/border" android:text="Item" /> </TableRow> </TableLayout>
这不会像你发布的照片完全一样,但是玩它可以得到你想要的.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。