如何在tablelayout中应用行跨度?

mig*_*uel 8 html java android row tablelayout

如何将row_span应用于TableLayout?

我想做一些类似于这个图像,但我不知道该怎么做.

表图像

制作这样的东西的正确方法是什么?

Com*_*are 20

TableLayout不支持行跨度,只支持列跨度.GridLayout支持行跨度和列跨度:

GridLayout示例

(图片来自http://android-developers.blogspot.com/2011/11/new-layout-widgets-space-and-gridlayout.html)


Jua*_*mez 5

很少作弊(代码可能非常复杂,只对简单设计有效):

做一个TableLayout.将另一个TableLayout放在第一列内,并将视图放在第二列中的rowspan中.这个内在TableLayout可以TableRows和你一样多,而另一个观点可以跨越.

这是代码:

<LinearLayout 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:orientation="vertical"
    android:padding="@dimen/activity_horizontal_margin"
    tools:context=".MainActivity">

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

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:weightSum="3">

            <TableLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1.5">

                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/holo_blue_dark">

                    <TextView
                        android:text="Row 1"/>

                </TableRow>

                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/holo_blue_light">

                    <TextView
                        android:text="Row 2"/>

                </TableRow>

                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/holo_blue_bright">

                    <TextView
                        android:text="Row 3"/>

                </TableRow>

            </TableLayout>

            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1.5"
                android:text="Second column, rowspan 3"
                android:background="@android:color/holo_purple"
                android:gravity="center"/>

        </TableRow>

    </TableLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

所以,总结:

TableLayout:第一列(TableLayout包含我们想要的TableRows),第二列(将占用所有这些行空间的元素).

在此输入图像描述