Measurespec Learning-Understanding of Integer.max_value >> 2 custom components

Source: Internet
Author: User
When customizing view and ViewGroup, we often encounter int-type MEASURESPEC to represent the size of a component, which has not only the size of the component, but also the pattern of the size.

This size pattern is a little hard to understand. There are three different sizes of components in the system:

1. Precise mode (measurespec.exactly)

In this mode, the size of the value is how much, then the length or width of this component is how much.

2. Max Mode (measurespec.at_most)

This is the parent component, can give the largest space, the current component of the maximum length or width can only be so large, of course, can be smaller than this.

3. No pattern specified (measurespec.unspecified)

This means that the current component, you can use space freely, unrestricted.

There may be a lot of people who can't figure out how an int integer can represent two things (size pattern and size value), an int type We know there are 32 bits. And the pattern has three kinds, must represent three kinds of states, at least 2 bit bits. The system then uses the highest 2-bit representation mode. As shown in figure:

> 2 Recognition _ Custom components >

A maximum of two digits is 00 when the "unspecified mode" is indicated. namely Measurespec.unspecified

A maximum of two digits is 01 when it means "exact mode." namely measurespec.exactly

The maximum of two digits is 10 when the "maximum mode" is represented. namely Measurespec.at_most

A lot of people once in place Operation Head is big, in order to operate simple, so the system provides me with a Measurespec tool class.

This tool class has four methods and three constants (shown above) for our use:

This is the size and pattern we give to generate an int variable that contains both of these two messages, and here This pattern is the parameter that passes one of the three constants.

public static int Makemeasurespec (int size, int mode)

This is to get the pattern information represented in this variable and compare the resulting value to three constants.

public static int GetMode (int measurespec)

This is the value that gets the size of the dimension represented in this variable.

public static int GetSize (int measurespec)

The pattern and size inside this variable are returned to the string to make it easy to log

public static String toString (int measurespec)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.