如何申请行跨度tablelayout?(How to apply row span in table

2019-08-31 15:29发布

如何申请row_span到TableLayout?

我要让类似这样的形象的东西,但我不知道该怎么做。

是什么力量让这样的事情的正确方法?

Answer 1:

TableLayout不支持行跨度,仅列跨越。 GridLayout支持行和列跨度:

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



Answer 2:

小作弊(也许相当复杂的代码,只适用于简单的设计):

做一个TableLayout 。 换个TableLayout的第一列,要在第二列的行跨度一个视图中。 这种内在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>

于是,涂总结:

TableLayout:第一列(TableLayout用,因为我们希望尽可能多的TableRows),第二列(即会占用所有的行空间元素)。



Answer 3:

你有没有使用“ 机器人:layout_span”它可以用来跨越行。 你无法通过Ctrl +空格键得到它,你需要手动输入。



文章来源: How to apply row span in tablelayout?