1

I'm just starting with android and could use some help.

I have a list of words that will always be between 20 and 30 words in length, and I want to display those words in columns on the screen, utilizing as much of the screen as possible. In portrait, having three columns seems to be the best size, and in landscape having five columns appears to be best. The words come from a dynamically created String array.

I am able to handle the orientation change programatically by calculating the optimal number of columns and rows then creating and adding all the LinearLayouts and TextViews, (three TextViews per layout in port, five in land) but I am curious as to whether it's possible to accomplish this using the layout-land / layout-port xml technique.

dgel
  • 16,352
  • 8
  • 58
  • 75

2 Answers2

0

I'd try using a TableLayout and specify TextView views as the TableRow views.. This would allow you to specify separate layouts in layout-port and layout-land as you need.

Squonk
  • 48,735
  • 19
  • 103
  • 135
  • I did consider this, but I don't know how I can have it dynamically sized (rows and columns) without programatically handling rotation. I am looking at GridView now, it looks promising. – dgel Oct 08 '11 at 21:01
  • Sorry, perhaps I misunderstood your question. I thought you'd decided 3 / 5 columns for portrait / landscape worked best. Based on that, I would create layouts of 3 columns x 10 rows for portrait and 5 columns x 6 rows for landscape. Then, based on actual number of words, I would collapse any rows which weren't needed. – Squonk Oct 08 '11 at 21:27
  • But wouldn't the collapsing need to be done manually in code during each orientation change? – dgel Oct 08 '11 at 21:29
  • Yes, you're correct - there would still need to be some code to adjust things. I think you're probably on the right tracks with `GridView` as you can fix the number of columns in the XML layout and it should dynamically create the correct number of rows. I'll withdraw this answer. – Squonk Oct 08 '11 at 21:34
0

If I where you I would use a listview. Maybe this thread could help you: Android: Populating a listview with array items

Community
  • 1
  • 1
Climbatize
  • 1,103
  • 19
  • 34