Nate Nate - 4 months ago 22
Android Question

Inserting vertical rows in TableLayout

I'm trying to add rows to a

TableLayout
in Android and the orientation property doesn't seem to work. Basically I need to create a
TableRow
, add multiple
TextView
s to it, and the add to the
TableLayout
and have the
TextView
s stacked vertically instead of horizontally.

The XML looks like this:

<TableLayout android:id="@+id/mylayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TableRow android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:text="Test1"></TextView>
<TextView android:text="Test2"></TextView>
</TableRow>
</TableLayout>


This seems like it should work, but the TextViews end up stacked left to right. Any thoughts?

Answer

I found a solution to this problem.I made a RelativeLayout and I am programmatically adding vertical orientation LinearLayout to it for each vertical row.I keep a handle to the control ID of the last inserted LinearLayout and insert the new one to the right of that ID. Feels a bit kludgy, but it works.