getMeasuredHeight()在Android 4.2.2返回16777215 [英] getMeasuredHeight() returns 16777215 on Android 4.2.2

查看:240
本文介绍了getMeasuredHeight()在Android 4.2.2返回16777215的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的LinearLayout作为下延伸的一个非常简单的ViewGroup。

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());

        }

这ViewGroup中的父是一个 RelativeLayout的包含一个简单的TextView。

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

在Android 4.2.2,parentLayout.getMeasuredHeight()返回16777215我不能够让这个数字的意义。它工作正常更高的Andr​​oid版本。

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.

有没有人遇到过这个?

推荐答案

我还没有看到这一点,但有一个记下哪些适合您的方案中的错误文档:

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

<一个href=\"http://developer.android.com/reference/android/view/View.MeasureSpec.html#makeMeasureSpec(int,%20int)\" rel=\"nofollow\">http://developer.android.com/reference/android/view/View.MeasureSpec.html#makeMeasureSpec(int,%20int)

至于16777215(等于2 ^ 24 - 1),我不知道,但它似乎是一个pretty大的巧合,它是等于 MEASURED_SIZE_MASK 。见

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

这篇关于getMeasuredHeight()在Android 4.2.2返回16777215的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆