自己继承ViewGroup实现一个视图。重写protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
发现执行该函数时widthMeasureSpec值为1073742304,heightMeasureSpec值为-2147482923。这两个值是什么意思?谢谢。

解决方案 »

  1.   

     /**
             * Measure specification mode: The parent has determined an exact size
             * for the child. The child is going to be given those bounds regardless
             * of how big it wants to be.
             */
            public static final int EXACTLY     = 1 << MODE_SHIFT;        /**
             * Measure specification mode: The child can be as large as it wants up
             * to the specified size.
             */
            public static final int AT_MOST     = 2 << MODE_SHIFT;
            private static final int MODE_SHIFT = 30;       那两个值是出自这个函数:
             private int getRootMeasureSpec(int windowSize, int rootDimension) {
            int measureSpec;
            switch (rootDimension) {        case ViewGroup.LayoutParams.FILL_PARENT:
                // Window can't resize. Force root view to be windowSize.
                measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.EXACTLY);
                break;
            case ViewGroup.LayoutParams.WRAP_CONTENT:
                // Window can resize. Set max size for root view.
                measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.AT_MOST);
                break;
            default:
                // Window wants to be an exact size. Force root view to be that size.
                measureSpec = MeasureSpec.makeMeasureSpec(rootDimension, MeasureSpec.EXACTLY);
                break;
            }
            return measureSpec;
        }
    具体啥意思,我也在研究....
      

  2.   

    已解决:
    Log.d("ANDROID_LAB",
    "onMeasure w_mode=" + MeasureSpec.getMode(widthMeasureSpec) + " w_size="
    + MeasureSpec.getSize(widthMeasureSpec) + " h_mode=" + MeasureSpec.getMode(heightMeasureSpec)
    + " h_size=" + MeasureSpec.getSize(heightMeasureSpec));
    其中getMode()返回值为:EXACTLY。
      

  3.   

    详见源代码:
    http://www.google.com/codesearch/p?hl=en#uX1GffpyOZk/core/java/android/view/View.java&l=9019
      

  4.   

    楼主得到的两个值其实就是屏幕的长宽+MeasureSpec类中的specMode的值.
    由此推断楼主设备的屏幕分辨率为:725*480
      

  5.   

    原来我搞错了,那是窗口的大小+MeasureSpec类中的specMode的值
      

  6.   

    嗯,是的。只是View的宽高,与分辨率无直接关系。