0

I'm creating a list view in Android where each row is shown with LinearLayout. The problem that I have is that since the text is different in each line, it isn't aligned in the same way. See for e.g. the "Date" - in different position on each line. What is the best way to create such a view?

Thanks in advance,

Noam

Layout

nambar
  • 573
  • 1
  • 5
  • 17

2 Answers2

1

Have a couple LinearLayouts in your row layout. Set their orientation to vertical and their layout_width to fill_parent. Also set their layout_weight to 1. These will act as columns and when you put stuff inside and for example center it it will always be in the same place.

Paweł Obrok
  • 22,568
  • 8
  • 74
  • 70
  • wouldn't that center them per row, and possibly not the same for each row? – Nanne Dec 18 '11 at 10:58
  • The problem that I have with weight is that it'll take extra space also if not needed. for e.g. I want that "Date" will take only the width that it is needed, leaving space to other columns. Basically, I'm looking for something similar to HTML table, when it'll match the width according to the content. – nambar Dec 18 '11 at 11:02
1

This is the same problem why browsers are slow with showing tables with variable width: you have to calculate the widths after you've parsed all content.

  • The quickest way is to manually assign a size (width) to your columns.
  • If you really can't do that because your content is very unpredictable (are you sure?) you could try and find out what the sizes should be from all your content, and then award the sizes.
Nanne
  • 64,065
  • 16
  • 119
  • 163