We learnt to make table with two rows and single column in the previous post. Now we will learn how to split the row into columns .
If you followed the previous tutorial to make a Table with single column , then making a Table with multiple columns is simple .
Step 1 : We just have to include two or more TextViews in a single TableRow . We will make a Table as shown in the below screenshot .
Step 2 : The file MainActivity.java remains the same as in the previous post
Step 3 : Just Run the project .
Step 1 : We just have to include two or more TextViews in a single TableRow . We will make a Table as shown in the below screenshot .
Add the code to activity_main.xml in res->layout .The code for the above screenshot is given below :
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" > <TextView android:id="@+id/TextView04" android:layout_weight="1" android:background="#00FF00" android:gravity="center" android:padding="5dip" android:text="HEADER 1" android:textColor="#000000" android:textStyle="bold" /> <TextView android:id="@+id/TextView04" android:layout_weight="1" android:background="#00FF00" android:gravity="center" android:padding="5dip" android:text="HEADER 2" android:textColor="#000000" android:textStyle="bold" /> </TableRow> <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" > <TextView android:id="@+id/TextView04" android:layout_weight="1" android:background="#b0b0b0" android:gravity="center" android:padding="5dip" android:text="ELEMENT 1" android:textColor="#000000" /> <TextView android:id="@+id/TextView04" android:layout_weight="1" android:background="#a09f9f" android:gravity="center" android:padding="5dip" android:text="ELEMENT 2" android:textColor="#000000" /> </TableRow> <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" > <TextView android:id="@+id/TextView04" android:layout_weight="1" android:background="#b0b0b0" android:gravity="center" android:padding="5dip" android:text="ELEMENT 3" android:textColor="#000000" /> <TextView android:id="@+id/TextView04" android:layout_weight="1" android:background="#a09f9f" android:gravity="center" android:padding="5dip" android:text="ELEMENT 3" android:textColor="#000000" /> </TableRow> </TableLayout>
Stay Tuned with Made In Android
No comments:
Post a Comment