I have a custom view. As expected, I override the onDraw and onMeasure . The onMeasure method looks like this:

 int w = View.MeasureSpec.getSize(widthSpec); int h = View.MeasureSpec.getSize(heightSpec); setMeasuredDimension(w, h); 

I can't figure out what the widthSpec and heightSpec parameters heightSpec . For example, I found that there are three constants:

 public static final int UNSPECIFIED = 0; public static final int EXACTLY = 1073741824; public static final int AT_MOST = -2147483648; 

But I get the values ​​of these spec- equal to 1073742704 (i.e., 0x40000370 in a hexadecimal system). What does this meaning mean?

    1 answer 1

    This is the result of the makeMeasureSpec function, which just packs the size and specification together. This is done to save memory (as written in the source) of the pack and unpack functions.

    To get mode use the function:

     getMode(int measureSpec) 

    A similar function is to get the size :

     getSize(int measureSpec) 

    Descriptions of these functions here.