Inserting a table row inside a table row
I want to insert two table rows inside a table row vertically. this is being done but the rows are being added horizontally instead of vertically. How to add vertical rows.. Following is my xml.
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/TableLAyout1"
>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TableRow
android:layout_column="0"
android:layout_width="fill_parent"
android:background="@drawable/eventbar"
android:layout_height="wrap_content"
开发者_开发百科 android:id="@+id/TableRow1" >
<TextView
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:text="Calendar for 14 August 2011"
android:layout_height="wrap_content"
android:textColor="@drawable/white"
android:layout_marginLeft="10dp"
/>
</TableRow>
<TableRow
android:layout_column="0"
android:layout_below="@+id/TableRow1"
android:layout_width="fill_parent"
android:background="@drawable/bgrow"
android:layout_height="wrap_content">
<ListView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/ListView2" >
</ListView>
</TableRow>
</TableRow>
</TableLayout>
Can anyone help me how to this?
I think you misunderstood how TableLayout
works. If you read up in the tutorial you will see, that TableLayout works similarly to HTML tables, meaning that TableRow
actually defines a row, not a column and is not even intended to do otherwise. The columns are created automatically based on the views you add to the rows.
Thus, if you want to have two rows with two TextViews
each, you just add two TableRow
s to your TableLayout
, and insert two TextView
s into each of them.
I think what you should do is have tableLayout inside the main table row and in the inner tablelayout you can have 2 rows and have the onclick event on the main tablerow. Even I am trying something like this, will update if it works.
精彩评论