android开发使用自定义view的时候,在部分机型上会报出这样的错误:
java.lang.IllegalStateException: onMeasure() did not set the measured dimension by calling setMeasuredDimension() at android.view.View.measure(View.java:18864) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:728) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:464) at android.view.View.measure(View.java:18849) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:728) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:464) at android.view.View.measure(View.java:18849) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435) at android.widget.LinearLayout.measureVertical(LinearLayout.java:721) at android.widget.LinearLayout.onMeasure(LinearLayout.java:612) at android.view.View.measure(View.java:18849) at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:2019) at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) at android.widget.ScrollView.onMeasure(ScrollView.java:487) at android.view.View.measure(View.java:18849) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904) at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) at android.view.View.measure(View.java:18849) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435) at android.widget.LinearLayout.measureVertical(LinearLayout.java:721) at android.widget.LinearLayout.onMeasure(LinearLayout.java:612) at android.view.View.measure(View.java:18849) at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:2019) at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) at android.widget.ScrollView.onMeasure(ScrollView.java:487) at android.view.View.measure(View.java:18849) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904) at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) at android.view.View.measure(View.java:18849) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904) at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) at android.view.View.measure(View.java:18849) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904) at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:447) at android.view.View.measure(View.java:18849) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904) at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:3073) at android.view.View.measure(View.java:18849) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2343) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1380) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1623) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1265) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6945) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:826) at android.view.Choreographer.doCallbacks(Choreographer.java:605) at android.view.Choreographer.doFrame(Choreographer.java:575) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:812) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:6837) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)应用里面使用的自定义view比较多,通过这个信息不能确定是什么地方出错了,有没有什么办法可以确定出错的位置?另外,在自动已的里面已经调用 setMeasuredDimension(int measuredWidth, int measuredHeight) 了或者super.onMeasure(widthMeasureSpec, heightMeasureSpec);了,会是什么原因造成的?求解答,谢谢!
从报错来说,你的确在 onMeasure中没有调用setMeasuredDimension方法,建议贴出代码看看######可能是编译的时候出的问题,重新编译过后就没有问题了
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。