下面是我的表代码。我的屏幕看起来像这样https://i.stack.imgur.com/U5ppn.jpg https://i.stack.imgur.com/U5ppn.jpg但我想让它看起来像这样https://i.stack.imgur.com/gFQZw.jpg https://i.stack.imgur.com/gFQZw.jpg。如何在每行和表格布局周围添加边框?
<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"));
为了在表格行和表格布局周围创建边框,您需要创建一个可绘制对象作为边框,然后将其设置为行的背景。
例如:
res/drawable/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="#ffffff"/>
<stroke android:width="1dp" android:color="#000000"/>
</shape>
资源/布局/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>
这看起来与您发布的图片不完全一样,但可以尝试一下以获得您想要的效果。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)