1

what I want is like a gridView where every item could have its own width. Like in html if you just add a lot of span items inside a div block, the div will just grow as necessary to fit them.

Is there something already built for this purpose or should I try and create my own AbsListView implementation?

LocoMike
  • 5,626
  • 5
  • 30
  • 43

2 Answers2

2

No, there is no such widget in Android.

Note that you would only extend AbsListView if you wanted individual items in the widget to be selectable. If you simply want a "flow layout", you would extend ViewGroup and create your own custom layout manager. There might already be an implementation of a "flow layout" available somewhere -- people have asked about it for a long time.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Hi, thanks for your answer. I guess I just did not know that I was looking for FlowLayout. Now I can see a lot of answers ;) Too bad anyway there is nothing build-in, as I guess this is a very common scenario. – LocoMike Jul 05 '11 at 10:38
  • @LocoMike: The reason you're seeing the term "flow layout" is that Swing had a container by that name that has the characteristics you seek. – CommonsWare Jul 05 '11 at 10:41
  • I have seen some ViewGroup implementations that have not really satisfied me, so I guess I will try and make my own AbsListView class. I am sure it will also be a very good exercise. Thanks! – LocoMike Jul 05 '11 at 22:48
  • 1
    @LocoMike: If by "very good exercise" you mean "requires Excedrin in industrial quantities", then, yes, I suspect that it'll be a "very good exercise"... :-) – CommonsWare Jul 05 '11 at 22:56
  • 1
    +1 for Excedrin. Extending AbsListView is nearly impossible for a developer not on the Android team. – user123321 Feb 14 '12 at 18:51
  • Note also that `ListView`s let you use `CursorAdapter`s, multiple selections and so on. On the other hand you actually *can't* extend `AbsListView` currently. So a custom `ViewGroup` is really the only way to go. (Actually you can copy all of `AbsListView` out of Android but apparently there are lots of dependencies. – Timmmm Sep 20 '12 at 14:00
1

Actually this question was answered here: Line-breaking widget layout for Android

I am using the RowLayout class (second answer), and it does the job very well.

Community
  • 1
  • 1
PatrickNLT
  • 4,075
  • 1
  • 25
  • 32