gpt4 book ai didi

android - getMeasuredHeight() 在 Android 4.2.2 上返回 16777215

转载 作者:行者123 更新时间:2023-11-29 01:35:07 28 4
gpt4 key购买 nike

我写了一个非常简单的 View 组扩展 LinearLayout 如下。

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

}

此 View 组的父级是包含简单 TextView 的 RelativeLayout

在 Android 4.2.2 上,parentLayout.getMeasuredHeight() 返回 16777215。我无法理解这个数字。它适用于更高版本的 Android。

有人遇到过这个吗?

最佳答案

我还没有看到这个,但是文档中有一个关于适合您的场景的错误的注释:

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

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

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

关于android - getMeasuredHeight() 在 Android 4.2.2 上返回 16777215,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28798288/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com