[英]Android tablelayout row padding
I want to create a table with buttons on the right of the rows as shown below. 我想在行的右侧创建一个带有按钮的表,如下所示。 I want to set padding for the right of each row but this "eats into" the right most button. 我想在每行的右侧设置填充,但这会“吃掉”最右边的按钮。 Is there a way of having the padding without compromising the display of the buttons? 有没有办法填充填充而不影响按钮的显示?
Here's my layout xml code: 这是我的布局xml代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp" >
<TableLayout
android:id="@+id/tbl_test"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="vertical"
android:layout_marginTop="1dp"
android:layout_marginBottom="1dp"
android:stretchColumns="1"
>
<TableRow android:background="#ffffff" android:layout_margin="1dp">
<TextView android:text="Col 1" android:layout_column="0" />
<TextView android:text="Col 2" android:layout_column="1" />
<TextView android:text="Col 3" android:layout_column="2" />
<TextView android:text="Col 4" android:layout_column="3" />
</TableRow>
<TableRow
android:background="#ffffff"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp">
<TextView android:text="r1" android:layout_column="0" />
<TextView android:text="padding right 0dp" android:layout_column="1" />
<Button android:text="edit" />
<Button android:text="delete" />
</TableRow>
<TableRow
android:background="#ffffff"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp"
android:paddingRight="2dp">
<TextView android:text="r2" android:layout_column="0" />
<TextView android:text="padding right 1dp" android:layout_column="1" />
<Button android:text="edit" />
<Button android:text="delete" />
</TableRow>
<TableRow
android:background="#ffffff"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp"
android:paddingRight="3dp">
<TextView android:text="r3" android:layout_column="0" />
<TextView android:text="padding right 2dp" android:layout_column="1" />
<Button android:text="edit" />
<Button android:text="delete" />
</TableRow>
<TableRow
android:background="#ffffff"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp"
android:paddingRight="4dp">
<TextView android:text="r4" android:layout_column="0" />
<TextView android:text="padding right 3dp" android:layout_column="1" />
<Button android:text="edit" />
<Button android:text="delete" />
</TableRow>
</TableLayout>
</RelativeLayout>
try 尝试
android:stretchColumns="0,1,2"
this would solve the problem after 这样可以解决问题
我不知道为什么剪辑的问题发生但是一个简单的方法来修复它并获得相同的外观是从TableRows
删除paddingRight
属性并在最后一个项目上添加属性layout_marginRight
(设置为填充值)行,删除Button
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.