溫馨提示×

android中tablelayout怎么合并單元格

小億
283
2024-04-18 18:12:10
欄目: 編程語言

在Android中,TableLayout中沒有直接支持合并單元格的功能。但是可以通過設置TableRow中的layout_span屬性來實現單元格的合并。下面是一個示例代碼:

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TableRow>

        <TextView
            android:text="Cell 1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>

        <TextView
            android:text="Cell 2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>

        <TextView
            android:text="Cell 3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>

    </TableRow>

    <TableRow>

        <TextView
            android:text="Merged Cell"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:layout_span="2"/>

        <TextView
            android:text="Cell 4"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>

    </TableRow>

</TableLayout>

在上面的示例中,第二行的第一個單元格被合并為一個單元格,通過設置layout_span屬性為2來實現合并效果。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女