Implementation of Android custom ViewGroup flowlayout streaming layout

Summarize from Hongyang's blog: http://blog.csdn.net/lmj623565791/article/details/38352503/ 1、 Flowlayout introduction the so-called flowlayout is that the control is automatically added to the right according to the width of the ViewGroup. If the remaining space of the current row is insufficient, it will be automatically added to the next row. It's a bit like all controls float to the left. The first line is full and float to the second line ~ so it's also called flow layout. Android does not provide streaming layout, but in some cases, streaming layout is very suitable for use, such as keyword tags, search hot word list, etc., such as the following figure:

There is a ready-made flowlayout on GitHub. This article is made from scratch.

2、 Production analysis

1. For flowlayout, you need to specify layoutparams. At present, we only need to be able to identify margin, that is, calculate the width and height of all childviews in marginlayoutparams. 2 and onmeasure, and then calculate their own width and height according to the width and height of childviews. (of course, if it is not wrap_content, you can directly use the calculated value passed in by the parent ViewGroup) 3. Layout all childviews in onlayout.

3、 Code 1. Mainactivity.java

2、CustomViewGroup.java

3、activity_ main.xml

4、activity_ main2.xml

5、activity_ main3.xml

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>