ScrollView嵌套ListView,listItem.measure(0,0);报空指针异常NullPointerException

来源:互联网 发布:计算机三级数据库 编辑:程序博客网 时间:2024/06/06 09:25
1: SrollView嵌套ListView时显示不全问题及ListView高度问题:直接上代码,使用以下函数解决此问题:
2: 当调用listItem.measure(0, 0);报空指针时问题:检查Adapter适配时Item的根容器为RelativeLayout,报错原因: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有三种解决方案:一、升级版本到4.2.2二、更改根容器为LinearLayout三、在适配器里添加convertView.setLayoutParams(new LayoutParams(                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); convertView为Item的view

0 0
原创粉丝点击