无法将垂直分隔符添加到TableLayout Android
我想将verdical分隔符添加到我的无法将垂直分隔符添加到TableLayout Android,android,xml,android-layout,tablelayout,android-tablelayout,Android,Xml,Android Layout,Tablelayout,Android Tablelayout,我想将verdical分隔符添加到我的表格布局 我的TableLayout如下所示: 但是我想在每行的两个textviews之间添加一行(分隔符)。我尝试在两个textviews之间放置一个视图,但它会拉伸行 以下是我对上述布局的代码: <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_heig
表格布局
我的TableLayout
如下所示:
但是我想在每行的两个textview
s之间添加一行(分隔符)。我尝试在两个textview
s之间放置一个视图
,但它会拉伸行
以下是我对上述布局的代码:
<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
或任何其他方式实现上述布局吗?这是主xml文件。你可以用
android:divider="@drawable/vertical_divider"
android:showDividers="middle"
以线性布局显示垂直分隔符。我设计了你的布局,我不喜欢表格布局,你可以试试线性布局
<?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>
这是密码
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>
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>
vertical_divider.xml
将颜色代码置于上方:)
输出
这是主xml文件。你可以用
android:divider="@drawable/vertical_divider"
android:showDividers="middle"
以线性布局显示垂直分隔符。我设计了你的布局,我不喜欢表格布局,你可以试试线性布局
<?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>
这是密码
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>
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>
vertical_divider.xml
将颜色代码置于上方:)
输出
我认为这个解决方案容易得多 您的表格布局:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:divider="@drawable/table_divider"
android:showDividers="middle"
android:shrinkColumns="*"
android:background="@drawable/rounded_corners">
<TableRow
android:divider="@drawable/table_divider"
android:showDividers="middle"
android:weightSum="3">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:padding="3dp"
android:text="Column1"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:padding="3dp"
android:text="Column2"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:padding="3dp"
android:text="Column3"
android:textStyle="bold" />
</TableRow>
<TableRow
android:divider="@drawable/table_divider"
android:showDividers="middle"
android:weightSum="3">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:padding="3dp"
android:text="Column1" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:padding="3dp"
android:text="Column2" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:padding="3dp"
android:text="Column3" />
</TableRow>
</TableLayout>
无背景的结果:
我认为这个解决方案容易得多 您的表格布局:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:divider="@drawable/table_divider"
android:showDividers="middle"
android:shrinkColumns="*"
android:background="@drawable/rounded_corners">
<TableRow
android:divider="@drawable/table_divider"
android:showDividers="middle"
android:weightSum="3">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:padding="3dp"
android:text="Column1"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:padding="3dp"
android:text="Column2"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:padding="3dp"
android:text="Column3"
android:textStyle="bold" />
</TableRow>
<TableRow
android:divider="@drawable/table_divider"
android:showDividers="middle"
android:weightSum="3">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:padding="3dp"
android:text="Column1" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:padding="3dp"
android:text="Column2" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:padding="3dp"
android:text="Column3" />
</TableRow>
</TableLayout>
无背景的结果:
谢谢你帮助我,但是我需要在第一个文本视图旁边的分配器,而不是中间部分。我该怎么做?我尝试过Android:St除除器=“开始”,但它仍然显示中间的垂直分隔符。尝试权重1.5和0.5,在具有水平方向的内部布局中添加权重和,并根据此代码更改文本视图的权重。谢谢你帮助我,但我需要除法器的第一个文本视图旁边,而不是在中间。我该怎么做?我尝试过Android:St除除器=“开始”,但它仍然显示中间的垂直分隔符。尝试权重1.5和0.5,在具有水平方向的内部布局中添加权重和,并根据此代码更改文本视图的权重。