Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of MeasureSpec in android

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is to share with you about the use of MeasureSpec in android. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

MeasureSpec plays an important role in the measure process of Android View. MeasureSpec is a 32-bit int, the first two bits represent the mode, where 00 represents UNSPECIFIED,01 represents EXACTLY,10 represents ATMOST, and the last 30 bits represent specific size, for example, the 1073741824 mode is EXACTLY, and the size is 1080.

What does measurespec mean?

In ViewGroup, there is a getChildMeasureSpec method to determine the MeasureSpec mode of the child view based on the MeasureSpec mode of the parent ViewGroup and the wrap_content, match_parent or xxdp of the child view. The specific rules are shown in the following figure. The second line is the parameter passed when the parent view calls the measure function of the child view. ChildSize is the size of the child view (yes, it is the marriage arranged by the father view, and the child view is only executed), and parentSize is the remaining size of the parent view (indicating the size of the child view. But do not exceed this size. 0 means that the parent view has no constraints on the child view and can be as big as it wants.

Measurespec's method

If you see these two pictures for the first time, you must be confused in the clouds. What do these modes have to do with wrap_content and match_parent in xml layout files? I'll try to explain the conversion process clearly. There are three ways to write wrap_content and match_parent,xxdp in the xml layout file. The program does not deal with these directly but converts them. When the program loads, it reads these parameters into the LayoutParams object and saves them, and then begins to traverse the entire view tree from the root view. The root view here is not the view we wrote in the xml file, but the built-in DecorView of the system. There are many layers between the view from DecorView to xml. However, it does not have much to do with the topic, we only need to know that the mode of the upper layer of view in the xml layout is EXACTLY (after all, the screen size is determined), according to the table above, if our layout is match_parent, then the mode is EXACTLY, if our layout is wrap_content, then the mode is AT_MOST. Knowing this premise and from the table above, we can easily infer what the mode of all view is and what the size should be.

Thank you for reading! This is the end of this article on "what is the use of MeasureSpec in android?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report