RelativeLayout执行measure(w,h)方法时,出现NullPointerException的异常情况
2016-02-01 11:55
531 查看
原文: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 RelativeLayout container 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-sdktag 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即可、
关于具体的核心解释,我也不太理解,希望大牛阅读到的时候能够回复一下,谢谢
版权声明:本文为博主原创文章,未经博主允许不得转载。
在编写下啦刷新的项目代码的时候,在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 RelativeLayout container 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-sdktag 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即可、
关于具体的核心解释,我也不太理解,希望大牛阅读到的时候能够回复一下,谢谢
相关文章推荐
- 解析C语言中空指针、空指针常量、NULL & 0的详解
- java 代码中预防空指针异常的处理办法
- 每周总结20130821——android控件的尺寸、http文件上传
- [学习笔记]C++空指针异常捕获
- 【java基础】引用类型数组初始化中,setter和getter函数空指针问题
- AMapNavi.getInstance(this) 返回值为null 的解决方法
- 段错误(segmentation fault)
- 0x00881789 处的第一机会异常(在 receive_filter.exe 中): 0xC0000005: 读取位置 0x00000000 时发生访问冲突。
- layoutinflater 空指针错误
- spinner notnullpoint 的出现
- File file=new File(filePath)报空指针
- 获取文件路径报空指针
- Storm OutputCollector并发问题导致NullPointerException的解决
- 空指针和野指针的区别
- 关于线程调用Spring注解对象报空指针异常
- 解决4.0以下继承PopupWindow报空指针的bug
- 关于C程序中空指针(null指针)的设计哲学
- 【android】null pointer exception
- 浏览根目录下index.jsp 报 空指针
- Android之自定义View,你需要了解和掌握的onMeasure测量规则