无法将垂直分隔线添加到 TableLayout Android [英] Cannot add Vertical Divider to TableLayout Android
问题描述
我想向我的 TableLayout
添加垂直分隔符.
I want to add verdical divider to my TableLayout
.
我的 TableLayout
看起来像这样:
My TableLayout
looks like this:
但我想在每行的两个 textview
之间添加一行(分隔线).我试过在两个 textview
之间放置一个 View
但它拉伸了行.
But i want to add a line (divider) between two textview
s in each row. I have tried placing a View
between two textview
s but it stretches the row.
这是我上面布局的代码:
Here is my code for the above layout:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/row"
android:layout_gravity="center"
android:showDividers="beginning"
android:orientation="horizontal"
android:stretchColumns="1"
android:background="@drawable/custom_background">
<TableRow>
<TextView
android:text="Name"
android:padding="3dip" />
<TextView
android:text="Imran"
android:gravity="left"
android:padding="3dip" />
</TableRow>
<View
android:layout_height="2dip"
android:background="#FF909090" />
<TableRow>
<TextView
android:text="Name"
android:padding="3dip" />
<TextView
android:text="Test"
android:gravity="left"
android:padding="3dip" />
</TableRow>
<View
android:layout_height="2dip"
android:background="#FF909090" />
<TableRow>
<TextView
android:text="Name"
android:padding="3dip" />
<TextView
android:text="Test"
android:gravity="left"
android:padding="3dip" />
</TableRow>
我想实现如下布局:
谁能帮助我使用 TableLayout
或任何其他方式实现上述布局?
Can anyone help me achieve the above layout using TableLayout
or any other way?
推荐答案
这里是主要的 xml 文件.你可以使用
Here is the main xml file. You can use
android:divider="@drawable/vertical_divider"
android:showDividers="middle"
在线性布局中显示垂直分隔线.我设计了你的布局,我不喜欢表格布局,你可以试试线性布局.
to display vertical divider in Linear layout. I have designed your layout, I don't like Table layout, You can try Linear layouts.
<?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="wrap_content"
android:background="@drawable/rounded_corner"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:divider="@drawable/vertical_divider"
android:showDividers="middle">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="16dp"
android:text="Lorem ipsum" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="16dp"
android:text="Lorem ipsum" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#FFCCCCCC"></View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@drawable/vertical_divider"
android:orientation="horizontal"
android:showDividers="middle">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="16dp"
android:text="Lorem ipsum" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="16dp"
android:text="Lorem ipsum" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#FFCCCCCC"></View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@drawable/vertical_divider"
android:orientation="horizontal"
android:showDividers="middle">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="16dp"
android:text="Lorem ipsum" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="16dp"
android:text="Lorem ipsum" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#FFCCCCCC"></View>
</LinearLayout>
这是
rounded_corner.xml
rounded_corner.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00000000" />
<stroke
android:width="1dp"
android:color="#bababa" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners
android:bottomLeftRadius="25dip"
android:bottomRightRadius="25dip"
android:topLeftRadius="25dip"
android:topRightRadius="25dip" />
</shape>
这是
vertical_divider.xml
<?xml version="1.0" encoding="UTF-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetBottom="2dp"
android:insetTop="2dp">
<shape>
<size android:width="1dp" />
<solid android:color="#FFCCCCCC" />
</shape>
</inset>
将您的颜色代码放在上面:)
Place your color codes above :)
输出
这篇关于无法将垂直分隔线添加到 TableLayout Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!