How to make a linear layout, add a child view to a new line?

I want to define a layout that is oriented horizontally, but if the width of the child views exceeds the width, it adds a new child view to a new row.

Can this be done?

+8
android layout
source share
4 answers

To do this, you will need FlowLayout, whose custom implementation is listed in this link.

Provided by: Nishant Nair

http://nishantvnair.wordpress.com/2010/09/28/flowlayout-in-android/

+13
source share

You can use RelativeLayout as the parent view and place many LinearLayouts in it, providing each of them with a separate identifier and adjusting their position relative to each other (in your case, โ€œbelowโ€).

+1
source share

NOp, :) not the way you want (not linear). I'm not sure, but I think that in java there was a FlowLayout that starts on the left and continues to move to the right when there is no free space, when a new line starts. But in android there is no such layout.

But you can do some workarounds for this problem. There are many different solutions, but this cannot be done with a linear layout. If you set the horizontal orientation, never skip to a new line.

as @Rasel suggested the best solution for you - use gridview and do nothing with orientation

0
source share

You can use the grid view as a layout to achieve this.

0
source share

All Articles