Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set number of columns in android tablelayout

I have the following code:

<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android: {code is required here}="2">

<TableRow>
    <TextView
        android:id="@+id/accelerometer_label"
        android: {code is required here}="1"
        android:text="Accelerometer"
        android:textSize="9pt"
        android:padding="3dip" />
</TableRow>

I am trying to get the data to display in three columns, any idea what code needs to go in the {code is required here} section?

like image 316
Scarlett Avatar asked May 15 '16 12:05

Scarlett


1 Answers

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:shrinkColumns="*"
    android:stretchColumns="*">

    <!-- Row 1 with single column -->
    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_span="3"
            android:background="#b0b0b0"
            android:padding="18dip"
            android:text="@string/row_1"
            android:textColor="#000"
            android:textSize="18sp" />


    </TableRow>

    <!-- Row 2 with 3 columns -->
    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_weight="1"
            android:background="#dcdcdc"
            android:gravity="center"
            android:padding="20dip"
            android:text="@string/row_2_column_1"
            android:textColor="#000000" />

        <TextView
            android:layout_weight="1"
            android:background="#d3d3d3"
            android:gravity="center"
            android:padding="20dip"
            android:text="@string/row_2_column_2"
            android:textColor="#000000" />

        <TextView
            android:layout_weight="1"
            android:background="#cac9c9"
            android:gravity="center"
            android:padding="20dip"
            android:text="@string/row_2_column_3"
            android:textColor="#000000" />

    </TableRow>

    <!-- Row 3 with 2 columns -->
    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal">

        <TextView
            android:layout_weight="1"
            android:background="#b0b0b0"
            android:gravity="center"
            android:padding="18dip"
            android:text="@string/row_3_column_1"
            android:textColor="#000000" />

        <TextView
            android:layout_weight="1"
            android:background="#a09f9f"
            android:gravity="center"
            android:padding="18dip"
            android:text="@string/row_3_column_2"
            android:textColor="#000000" />
    </TableRow>

 </TableLayout>
like image 79
Mrugesh Thaker Avatar answered Oct 16 '22 20:10

Mrugesh Thaker