Android 在Java代码中实现TableRow的间距
时间: 2024-02-27 20:53:28 浏览: 89
Android 的 TableRow 默认是没有间距的,如果要设置间距,可以通过设置 TableRow 的 layout_margin 属性来实现。具体步骤如下:
1. 在 XML 布局文件中,为 TableRow 设置 layout_margin 属性,例如:
```
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
...
</TableRow>
```
这样就为 TableRow 设置了上下间距为 8dp。
2. 如果要为 TableRow 中的每个单元格设置间距,可以在单元格中添加一个空的 TextView,并设置其 layout_margin 属性,例如:
```
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"/>
...
</TableRow>
```
这样就为每个单元格设置了左右间距为 8dp。注意,要将 TextView 的 layout_width 设置为 0dp,并设置 layout_weight 属性,以使其自适应 TableRow 的宽度。
阅读全文
相关推荐


















