Android tablelayout 行填充

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12451518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:41:31  来源:igfitidea点击:

Android tablelayout row padding

androidandroid-tablelayout

提问by

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?

我想在行的右侧创建一个带有按钮的表格,如下所示。我想为每一行的右侧设置填充,但这“吞噬”了最右边的按钮。有没有办法在不影响按钮显示的情况下使用填充?

Screen shot of the table layout

表格布局的屏幕截图

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>

采纳答案by Luksprog

I don't know why the problem with the clipping happens but one easy way to fix it and obtain the same appearance is to remove the paddingRightattribute from the TableRowsand also add the attribute layout_marginRight(set to the padding value) on the last item of the row, the delete Button.

我不知道为什么会出现裁剪问题,但修复它并获得相同外观的一种简单方法是从 中删除该paddingRight属性,TableRowslayout_marginRight在该行的最后一项上添加该属性(设置为填充值) ,删除Button

回答by Aslam Shahid

try

尝试

android:stretchColumns="0,1,2"

this would solve the problem after

这将解决问题之后