Sathish Kumar J Sathish Kumar J - 5 months ago 12
Android Question

How to create TableLayout in android similarly Html Table

I created table like following by the use of

Html
Code,

table_using_html

Now, How to do like this in Android with using
TableLayout
.

Note:
If needed i'll post my
html
code.

Cgx Cgx
Answer

Use GridLayout

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:rowCount="3"
android:columnCount="3"
android:layout_height="wrap_content">

<Button
    android:text="1"
    android:background="#00f"
    android:layout_height="wrap_content"
    android:layout_gravity="fill"
    android:layout_rowSpan="2"
    android:layout_width="wrap_content"/>
<Button
    android:text="2"
    android:layout_columnSpan="2"
    android:layout_gravity="fill"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"/>
<Button
    android:text="3"
    android:layout_gravity="fill"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"/>
<Button
    android:text="4"
    android:layout_rowSpan="2"
    android:layout_gravity="fill"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"/>
<Button
    android:text="5"
    android:layout_gravity="fill"
    android:layout_columnSpan="2"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"/>

</GridLayout>

Output

enter image description here