![](/img/trans.png)
[英]Android: How to equally divide the table layout height to table rows in programmatically
[英]How to merge two rows in android table layout
我想知道如何在 android 表格布局中合並兩行。 我知道 android:layout_span 用於合並列以及用於合並兩行的屬性是什么?
TableLayout
沒有 rowspan 屬性。 最好使用LinearLayout
或RelativeLayout
。 這要簡單得多。 或者使用GridLayout
for API Level > 13
如果您依賴TableLayout
,則可以按如下方式實現行跨度:
<TableLayout ...>
<TableRow..>
<!-- Column 1 : Rowspan 2 -->
<TextView .../>
<!-- Column 2 : 2 Rows -->
<TableLayout ...>
<TableRow..>
<TextView .../>
</TableRow>
<TableRow..>
<TextView .../>
</TableRow>
</TableLayout>
</TableRow>
</TableLayout>
使用LinearLayouts
解決方案(便宜且簡單):
<LinearLayout
...
android:orientation="horizontal">
<!-- Column 1 -->
<LinearLayout
...
android:orientation="vertical">
<TextView .../>
</LinearLayout>
<!-- Column 2 -->
<LinearLayout
...
android:orientation="vertical">
<TextView .../>
<TextView .../>
</LinearLayout>
</LinearLayout>
抱歉回復一個舊帖子。 這對我有用:
<TableLayout>
<TableRow>
<TextView
android:text="Single L"
android:layout_column="1"/>
<TextView
android:text="Single R"
android:layout_column="2"/>
</TableRow>
<TableRow>
<TextView
android:text="Double"
android:layout_span="2"
android:layout_weight="2"/>
</TableRow>
</TableLayout>
希望有人會覺得它有用。
PS:注意底層元素必須包含span
+ weight
或指定的column
值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.