29

I have a horizontal linear layout that contains textviews generated dynamically, the problem I'm experiencing is that the textviews are squeezed (see image below) if too many of them are added. How would I go about wrapping the linearlayout so that the textviews are printed on the next line?

enter image description here

A--C
  • 36,351
  • 10
  • 106
  • 92
Anton
  • 820
  • 1
  • 8
  • 13

3 Answers3

7

LinearLayout cant help with this. Instead you will have make your own Layout as mentioned in this http://nishantvnair.wordpress.com/2010/09/28/flowlayout-in-android/ or incorporate the same approach as of this Android - LinearLayout Horizontal with wrapping children

Community
  • 1
  • 1
Avinazz
  • 372
  • 2
  • 14
  • 1
    Thanks for the 2nd link, perfect description of how to handle creating an new horizontal layout. NOTE: view.getMeasuredWidth() will return 0 if you DO NOT set view.measure(0,0) beforehand. – Anton Jan 25 '13 at 20:16
7

FlexboxLayout is a library project which brings the similar capabilities of CSS Flexible Box Layout Module to Android.

https://github.com/google/flexbox-layout

Similar question:

Line-breaking widget layout for Android

Darush
  • 11,403
  • 9
  • 62
  • 60
2

This project is nice because you can just add the Gradle compile directive for the project, and be able to use the FlowLayout in the Xml from there. No need to copy in Java files

https://github.com/ApmeM/android-flowlayout

Gene Bo
  • 11,284
  • 8
  • 90
  • 137