How to apply row span in tablelayout?
Asked Answered
R

2

12

How to apply row_span to TableLayout?

I want to make something similar to this image, but i don't know how to do it.

table image

What is the correct way to make something like this?

Romanticism answered 20/4, 2013 at 23:19 Comment(3)
seems like a possible duplicate #2190486Hammerfest
Is not duplicated. That's not the answer to the question I asked.Romanticism
did you got any solution for thisMckelvey
D
25

TableLayout does not support row spans, only column spans. GridLayout supports both row and column spans:

GridLayout sample

(picture from http://android-developers.blogspot.com/2011/11/new-layout-widgets-space-and-gridlayout.html)

Defend answered 20/4, 2013 at 23:38 Comment(0)
T
8

Little cheating (maybe quite complex to code and only valid for a simple design):

Make a TableLayout. Put another TableLayout inside the first column and a view that you want to have the rowspan in the second column. This inner TableLayout can have as many TableRows as you whish the other view to span.

Here's the code:

<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>

So, tu sum up:

TableLayout: first column (TableLayout with as many TableRows as we want), second column (element that will take up all those rows' space).

enter image description here

Tulley answered 25/4, 2015 at 22:39 Comment(3)
i missed something ? how u make two rows == two columns ? u should put two table layouts in one row to achieve two columns then in nested tablelayout put rows & in second tablelayout one row or any other content. then in second row set span=2Decillion
I'm sorry. it's a mistake. I meant two columns, not two rows. The thing is, the first column contains a TableLayout with as many rows as you want to span and the second column contains only one view. I'll edit.Dejesus
Using this for a row list item just what I needed haFoulup

© 2022 - 2024 — McMap. All rights reserved.