2

I have written a very simple viewgroup extending LinearLayout as below.

 @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {



        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        ViewParent viewParent  = getParent();
        if(viewParent instanceof RelativeLayout)
        {
            RelativeLayout parentLayout  = (RelativeLayout)viewParent;

            int widthSize = MeasureSpec.getSize(widthMeasureSpec);


            Log.d(Constants.TAG, "Parent height is " + parentLayout.getMeasuredHeight());
            Log.d(Constants.TAG, "Parent height is1 " + parentLayout.getHeight());
            int height = parentLayout.getMeasuredHeight();
//            getChildAt(0).measure(MeasureSpec.EXACTLY | AndroidUtilities.dp(70), MeasureSpec.EXACTLY | (int)(parentLayout.getMeasuredHeight()*0.6));
 //           getChildAt(1).measure(MeasureSpec.EXACTLY | AndroidUtilities.dp(70), MeasureSpec.EXACTLY | (int)(parentLayout.getMeasuredHeight()*0.4));

            getChildAt(0).measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(70), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int)(height* 0.6), MeasureSpec.EXACTLY));
            getChildAt(1).measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(70), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int)(height* 0.6), MeasureSpec.EXACTLY));


            setMeasuredDimension(widthSize, parentLayout.getMeasuredHeight());

        }

The parent of this viewgroup is a RelativeLayout containing a simple TextView.

On Android 4.2.2, parentLayout.getMeasuredHeight() returns 16777215. I am not able to make the sense of this number. It is working fine for higher Android versions.

Has anyone encountered this before?

Madhur Ahuja
  • 22,211
  • 14
  • 71
  • 124

1 Answers1

1

I haven't seen this, but there's a note in the docs about a bug which fits your scenario:

http://developer.android.com/reference/android/view/View.MeasureSpec.html#makeMeasureSpec(int,%20int)

As for 16777215 (which equals 2^24 - 1), I'm not sure, but it seems like a pretty big coincidence that it's equal to MEASURED_SIZE_MASK. See

http://developer.android.com/reference/android/view/View.html#MEASURED_SIZE_MASK

peterrhodesdev
  • 241
  • 4
  • 14