Is there and any method to make table like html in android where i can set row column width as we do in html
<table >
<tr><td style="width:'50%;"></td>
<td style="width:'50%;"></td>
</tr>
</table>
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="3" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
</TableLayout>
Edit 1:
For something like Html there the percentage width works with respect to its Parent
but the weight introduced in Android works with respect to the screen size available for root.
Android TableLayout going to be arranged groups of views into rows and columns. You will use the <TableRow> element to build a row in the table. Each row has zero or more cells; each cell can hold one View object. TableLayout containers do not display border lines for their rows, columns, or cells.
To change the width to a specific measurement, click a cell in the column that you want to resize. On the Layout tab, in the Cell Size group, click in the Table Column Width box, and then specify the options you want.
A layout that arranges its children into rows and columns. A TableLayout consists of a number of TableRow objects, each defining a row (actually, you can have other children, which will be explained below). TableLayout containers do not display border lines for their rows, columns, or cells.
This example demonstrates how create a table with borders in Android . Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
The TableLayout has properties similar to LinearLayout. I did some tweek on it too. To better say it, see my sample code below. Hope its useful.
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="3" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<TextView android:text="@string/test1" android:layout_weight="1"></TextView>
<TextView android:text="@string/test2" android:layout_weight="1"></TextView>
<TextView android:text="@string/test3" android:layout_weight="1"></TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<TextView android:text="@string/test1" android:layout_weight="1"></TextView>
<TextView android:text="@string/test2" android:layout_weight="1"></TextView>
<TextView android:text="@string/test3" android:layout_weight="1"></TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<TextView android:text="@string/test1" android:layout_weight="1"></TextView>
<TextView android:text="@string/test2" android:layout_weight="1"></TextView>
<TextView android:text="@string/test3" android:layout_weight="1"></TextView>
</TableRow>
</TableLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With