How to apply row range in tablelayout?

How to apply row_span to TableLayout?

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

table image

What is the correct way to do something like this?

+6
source share
3 answers

TableLayout does not support row scrolling, only columns. GridLayout supports both rows and columns:

GridLayout sample

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

+15
source

A little trick (possibly a rather complex code and only valid for simple design):

Make a TableLayout . Put another TableLayout in the first column and the view you want rowspan in the second column. This internal TableLayout can have as many TableRows as you want the other view to display.

Here is 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: the first column (TableLayout with as many tables as we want), the second column (an element that will occupy the entire space of these rows).

enter image description here

+4
source

Do you use " android: layout_span ", it can be used to span strings. You cannot get it with Ctrl + Space, which you need to enter manually.

0
source

All Articles