How to create “floating TextViews” in Android?

删除回忆录丶 提交于 2019-12-10 11:33:40

问题


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!


回答1:


It sounds like you're looking for something like a FlowLayout in Java? I found an answer in this question that looks immensely helpful for what you're trying to do.




回答2:


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.



来源:https://stackoverflow.com/questions/4627422/how-to-create-floating-textviews-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!