Android Jelly Bean MeasureSpec 错误

标签 android android-4.3-jelly-bean android-4.2-jelly-bean

我遇到了这个问题:https://stackoverflow.com/questions/20121696/slidingmenu-bug-in-android-4-3
但现在我已经修复了,我想分享我的解决方案,因为可能有人也需要它。
下面我将亲自回答这个问题。

最佳答案

所以我遇到的问题在于当我们想要创建 MeasureSpec 时 Build.VERSION_CODES.JELLY_BEAN_MR2 有问题:

MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams..., MeasureSpec.EXACTLY);

MeasureSpec.EXACTLY 当我执行例如 .measure(widthMeasureSpec, heightMeasureSpec); 它返回的值完全奇怪,所以如果我们使用这个问题就可以解决MeasureSpec.AT_MOST 而不是 MeasureSpec.EXACTLY


希望它对以后的人有帮助;)
ps:不知道Android Kitkat(4.4,API 19)是否也有这个问题。

编辑:确实如此。

int widthMeasureSpec;
int heightMeasureSpec;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
    widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.MATCH_PARENT, View.MeasureSpec.AT_MOST);
    heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.AT_MOST);
} else {
    widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.MATCH_PARENT, View.MeasureSpec.EXACTLY);
    heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.EXACTLY);
}

关于Android Jelly Bean MeasureSpec 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20147938/

相关文章:

android - set.addAll(myArrayList) 不按相同顺序添加列表项

android - 未收到 ACTION_MY_PACKAGE_REPLACED

Android 4.3 LE 蓝牙客户端服务器冲突

android - Jelly Bean android.R.id.content 改变了吗?

android-edittext - Desire HD 中的应用程序崩溃

android - 开发 Android 游戏的正确方法

Android screenOrientation API 18 - "nosensor"与 "locked"和 "unspecified"与 "user"与 "fullUser"

java - OnFrameAvailable 回调未到来

android - CyanogenMod10 如何确定来电者的位置?

android - 旋转端口登陆Android4.X后如何避免在智能手机中剪切/复制/粘贴?