RelativeLayout执行measure(w,h)方法时,出现NullPointerException的异常情况
来源:互联网 发布:温度检测软件 编辑:程序博客网 时间:2024/06/05 14:44
写视差回弹ListView时遇到的问题,给ListView添加header时,使用header.measure(0,0)方法时有的手机没问题,有的就不行,提示NullPointerException
10-21 16:35:38.031: E/AndroidRuntime(4208): java.lang.NullPointerException
10-21 16:35:38.031: E/AndroidRuntime(4208): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:548)
10-21 16:35:38.031: E/AndroidRuntime(4208): at android.view.View.measure(View.java:15848)
搜了一下,发现有人也遇到了,记录一下:转自:http://blog.csdn.net/ljz2009y/article/details/18351491
在编写下啦刷新的项目代码的时候,在Listview的HeaderView中的head.xml文件中,根布局为RelativeLayout的时候,在计算headerView.measure的时候,出现空指针异常,当将更布局改为Linearlayout就运行正常了。
在思考为何在RelativeLayout出现异常的问题的时候,在查阅官方网站的时候,我注意到这个段话:
Note: In platform version 17 and lower, RelativeLayout was affected by a measurement bug that could cause child views to be measured with incorrect MeasureSpec
values. (See MeasureSpec.makeMeasureSpec
for more details.) This was triggered when a RelativeLayoutContainer was placed in a scrolling container, such as a ScrollView or HorizontalScrollView. If a custom view not equipped to properly measure with the MeasureSpec mode UNSPECIFIED
was placed in a RelativeLayout, this would silently work anyway as RelativeLayout would pass a very large AT_MOST
MeasureSpec instead.
This behavior has been preserved for apps that set Android:targetSdkVersion="17"
or older in their manifest's uses-sdk
tag for compatibility. Apps targeting SDK version 18 or newer will receive the correct behavior
在android系统版本在17级以下(包含17的时候)。使用measure会出现NULL异常情况,这个是一个BUG。原因是在RelativeLayout的控件使用在含有scrolling的时候,该含有scrolling的控件中计算空间大小的时候,没有使用MeasureSpec mode UNSPECIFIED的布局方式在RelativeLayout。自定义的控件则会尽可能的使用
AT_MOST
来替换对齐方式。
如果你想解决这个问题有2个方法:
1.讲SDK的目标版本升级
2.将需要使用RelativeLayout的上层包一个LinearLayout即可、
关于具体的核心解释,我也不太理解,希望大牛阅读到的时候能够回复一下,谢谢
- RelativeLayout执行measure(w,h)方法时,出现NullPointerException的异常情况
- RelativeLayout执行measure(w,h)方法时,出现NullPointerException的异常情况
- RelativeLayout执行measure(w,h)方法时,出现NullPointerException的异常情况
- RelativeLayout执行measure(w,h)方法时,出现NullPointerException的异常情况
- RelativeLayout执行measure(w,h)方法时,出现NullPointerException的异常情况
- android开发中遇到的问题解决之RelativeLayout执行measure(w,h)方法时,出现NullPointerException的异常情况
- Android RelativeLayout.mesure()时出现NullPointerException异常
- RelativeLayout在调用measure方法时报空指针异常java.lang.NullPointerException
- Android 4.3(API 18)及以下调用 RelativeLayout.mesure() 时出现 NullPointerException 异常
- Android兼容性问题 -- RelativeLayout.mesure()出现NullPointerException异常
- Android: NullPointerException when using RelativeLayout with measure()
- Android: NullPointerException when using RelativeLayout with measure()
- 调用 RelativeLayout measure()报 java.lang.NullPointerException
- Android: NullPointerException when using RelativeLayout with measure()
- tabhost TabSpec执行setContent时出现空指针异常NullPointerException
- 含有RelativeLayout的View.measure()空指针异常
- android.widget.RelativeLayout.onMeasure出现的java.lang.NullPointerException错误
- Android 关于RelativeLayout.onMeasure出现的NullPointerException错误
- 【江哥带你从“零”玩转Html5 + 跨平台开发】火热更新中···
- Perl常用模块总结
- qt小事记2——菜单栏
- jquery 弹出浮层(div) + 遮蔽层
- JBOSS中配置JNDI数据源
- RelativeLayout执行measure(w,h)方法时,出现NullPointerException的异常情况
- Thinkphp5 联合(关联)查询
- plt实例
- Activity生命周期
- 内核中通过虚拟地址找到物理地址例子
- 安装redmine
- 爱她,就送她ifunk
- cpp继承和多态
- Android UI线程时间多少毫秒才不会卡顿