How to create "floating TextViews" in Android?

Dennis Winter picture Dennis Winter · Jan 7, 2011 · Viewed 11.4k times · Source

I'm programmatically putting various TextViews into a LinearLayout with a horizontal orientation.

After 2h of research I couldn't find out how to tell Android not to squeeze all the TextViews in one line but instead to "float" non-fitting TextViews into the next line.

I know there isn't something like actual "lines" in a LinearLayout, but how can I tell the TextViews to actually behave like floating DIVs from the HTML world?

Thanks alot!

Answer

Charlie Collins picture Charlie Collins · Jan 7, 2011

Use RelativeLayout. In addition to allowing to you to set up Views relative to each other, it can also align them relative the parent.

Specifically, look at RelativeLayout.LayoutParams, with which you can do something similar to float with alignParentRight/alignParentLeft and so on.