Table Layout in Android
In this post you will understand how to create a Table Layout in Android. Here i did the design in XML. Coding is little bit tricky but interesting.Coding- main.xml
<TableLayout 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:background="#ffffff"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="100dp" >
<TextView
android:id="@+id/TextView04"
android:layout_weight="1"
android:background="#dcdcdc"
android:gravity="center"
android:padding="20dip"
android:text="R1 c1"
android:textColor="#000000" />
<TextView
android:id="@+id/TextView04"
android:layout_weight="1"
android:background="#d3d3d3"
android:gravity="center"
android:padding="20dip"
android:text="R1 c2"
android:textColor="#000000" />
<TextView
android:id="@+id/TextView04"
android:layout_weight="1"
android:background="#d3d3d3"
android:gravity="center"
android:padding="20dip"
android:text="R1 c2"
android:textColor="#000000" />
</TableRow>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="100dp" >
<TextView
android:id="@+id/TextView04"
android:layout_weight="1"
android:background="#dcdcdc"
android:gravity="center"
android:padding="20dip"
android:text="R1 c1"
android:textColor="#000000" />
<TextView
android:id="@+id/TextView04"
android:layout_weight="1"
android:background="#d3d3d3"
android:gravity="center"
android:padding="20dip"
android:text="R1 c2"
android:textColor="#000000" />
<TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/TextView04"
android:layout_weight="0.5"
android:background="#dcdcdc"
android:gravity="center"
android:padding="5dip"
android:text="R1 c3"
android:textColor="#000000" />
<TextView
android:id="@+id/TextView04"
android:layout_weight="0.5"
android:background="#dcdcdc"
android:gravity="center"
android:padding="5dip"
android:text="R1 c4"
android:textColor="#000000" />
</TableRow>
</TableRow>
</TableLayout>
------------------------------------------------------------------------------------------------
This is the Output for the above XML coding
No comments:
Post a Comment