Android simply implements an example of a streaming layout

This article mainly introduces an example of simply implementing a streaming layout for Android, which is shared with you as follows:

Streaming layout should be a very common layout, which will be encountered in many scenarios, such as functions such as labels. It's better to build a wheel than to use a wheel. Here you can simply realize the obscene layout:

Through the above two methods, we can complete the basic operation of convective layout:

onMeasure

In the onmeasure method, it is responsible for setting the measurement mode and size of child controls, and setting their own width and height according to all child controls. Once the width exceeds the maximum width, line wrapping will be carried out. The height is continuously accumulated to obtain the final height.

onLayout

The onlayout method is used to lay out the sub views. On the premise, we must know the width and height of each sub view. Therefore, we must first measure the specific size of each sub view during onmeasure.

test

Here, we should note that flowlayout.layoutparam params = new flowlayout.layoutparam (ViewGroup. Layoutparams. Wrap_content, ViewGroup. Layoutparams. Wrap_content); Some small partners may not be able to point out this method in the process of writing. That is because we need to write a static internal class to implement this method.

Well, such a simple streaming layout is over. Sometimes I knock it out myself and realize it. I find that I will learn a lot. The code tested here is a view added in a loop. You can also try to write an adapter like way to implement it. Paste the source code for reference.

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
分享
二维码
< <上一篇
下一篇>>