Listview item.measure(0, 0);报空指针时问题
2017-09-13 10:33
369 查看
做了一个截取ListView内容保存为图片的功能,测试的时候发现4.2的模拟器上报错,查看一番之后发现是计算item时候报空指针,查到的解决方案如下:
转载地址:解决方案
当调用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
转载地址:解决方案
当调用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
相关文章推荐
- 解决ListView 跟ScroolView 共存 listItem.measure(0, 0) 空指针
- 解决ListView 和ScroolView 共存 listItem.measure(0, 0) 空指针
- 解决ListView 跟ScroolView 共存 listItem.measure(0, 0) 空指针
- 解决ListView 跟ScroolView 共存 listItem.measure(0, 0) 空指针
- 解决ListView 和ScroolView 共存 listItem.measure(0, 0) 空指针
- 解决ListView 跟ScroolView 共存 listItem.measure(0, 0) 空指针
- 解决ListView 跟ScroolView 共存 listItem.measure(0, 0) 空指针
- 解决ListView 跟ScroolView 共存 listItem.measure(0, 0) 空指针
- listItem.measure(0, 0) 空指针问题
- 在popupWindow中使用ListView时对ItemView设置fill_parent不起作用的问题
- 解决ListView的item监听事件个子控件监听事件冲突问题
- Android ListView的Item点击事件和Item里控件点击事件冲突问题解决
- listview中item 有checkbox多选防止滑动 listview页面 出现checkbox错位问题
- ListView滑动时 item出现黑色背景的问题的解决方法
- 关于listView 每个item 加载Html的问题
- Android布局中ScrollView与ListView的冲突的最简单方法(listItem.measure(0, 0))
- 关于ListView+CheckBox,Item超过一屏时数据乱序和不能全部选中的问题
- 接入百度广告sdk遇到开屏广告黑屏和listView item高度不生效问题
- Android中设置Listview的item之间透明及item点击无响应问题
- ListView item布局不能居中问题