【发布时间】:2019-05-10 10:55:13
【问题描述】:
我正在尝试创建一个屏幕,以表格格式显示学生及其在不同科目中的相应分数。如何创建垂直和水平分隔线?
【问题讨论】:
标签: android tablelayout
我正在尝试创建一个屏幕,以表格格式显示学生及其在不同科目中的相应分数。如何创建垂直和水平分隔线?
【问题讨论】:
标签: android tablelayout
您正在寻找如何围绕表格行和表格布局创建边框。而不是分频器。 您必须创建一个可绘制对象作为边框,然后将其设置为背景。 她的解决方案:
res/drawable/shape_table.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>
您的 Layout.xml
<TableLayout
....>
<TableRow
....
android:background="@drawable/shape_table">
<TextView
...
android:background="@drawable/shape_table"
/>
<TextView
...
android:background="@drawable/shape_border"
/>
</TableRow>
</TableLayout>
如果您正在寻找一个分隔线,您可以使用 垂直:
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#c0c0c0"/>
水平:
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#c0c0c0"/>
【讨论】:
在每行项目之后使用此代码
XML 中的水平线
<View android:layout_width="match_parent"
android:background="@android:color/red"
android:layout_height="2dp" />
XML 中的垂直线
<View android:layout_width="2dp"
android:background="@android:color/red"
android:layout_height="match_parent"/>
【讨论】: