开发者

Having a TableRow with TextView's underneath each other

I'm currently having the following problem:

I've got a TableView that is given TableRow's to be added to it with data. I want each TableRow to contain 2 TextView's having a width of the parent and are underneath each other, for example:

| TextView1.............. |
| TextView2.............. |
| .........EndOfTextView2 |

In my example above, it's just showing that I also want the second TextView to be able to run over multiple lines.

Here is the XML for my Tab开发者_JAVA百科leLayout:

<TableLayout
      android:id="@+id/feed"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_margin="5px"
      android:stretchColumns="1"
>
</TableLayout>

Used to iOS so I'm kind of new in this XML/Java style mobile programming department.

EDIT:

I ended up adding a LinearLayout to the TableRow, is this the best way to do it?


You have several ways to do it:

  • Adding a vertical LinearLayout to each row is one.
  • Another option is not to use a TableLayout, but do everything with a RelativeLayout.
  • A third one is to use a ListView instead of a TableLayout (since, as it looks like, you're using just one cell per row).

The links above are for the android site tutorials for ListView and RelativeLayout.

Pros/Cons:

  • The first option is the easiest to implement, but is not really efficient.
  • The second one has the advantage of using less layouts, thus increasing performance and reducing memory usage, but it will take some time to get it right.
  • The third one is the most flexible if the rows will be changing dynamically. The con is that it would require a custom adapter for your two lines of text (adding a little complexity to your first program).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜