解决scrollview嵌套listview ,listview异常,数据不显示,高度异常,布局异常
2017-07-07 14:17
561 查看
我们在开发中会经常遇到一些嵌套使用,但是每个嵌套不是简单的嵌套就能正常使用的,博主作为一个菜鸡在最初的学习阶段 真是难啊!
一遇到不正常的 现象,又不崩溃,打日志没问题,打debug没问题,参看xml文件没问题,可就为啥啥都没有呢。以为网络数据没加载出来,
。只怪自己太菜。
嵌套使用需谨慎啊,可能事件分发冲突,也可能导致布局, UI,异常。 本次 提供一个解决 ListView和ScrollView 方法。
下一次:提供一个解决事件分发冲突的 解决办法。
一遇到不正常的 现象,又不崩溃,打日志没问题,打debug没问题,参看xml文件没问题,可就为啥啥都没有呢。以为网络数据没加载出来,
。只怪自己太菜。
嵌套使用需谨慎啊,可能事件分发冲突,也可能导致布局, UI,异常。 本次 提供一个解决 ListView和ScrollView 方法。
/** * Created by shangbeibei on 2016/12/13. * <p>遇到ScrollView和ListView 计算高度</p> */ public class SetListViewHeightUtils { public static SetListViewHeightUtils setHeight; public static synchronized SetListViewHeightUtils getInstence(){ if (setHeight ==null){ setHeight =new SetListViewHeightUtils(); } return setHeight; } /**[注意] 此方法应当在所有adapter 操作之后 在执行 * <p>因为ListView和ScrollView(PullToZoomScrollViewEx)的 原因,发现在ScrollView(PullToZoomScrollViewEx)中嵌套ListView空间, * 无法正确的计算ListView的大小,故可以通过代码,根据当前的ListView的列表项计算列表的尺寸</p> * ps:也可以直接试用 PullToZoomListViewEx */ public void initListViewHight(ListView listview) { ListAdapter listadapter = listview.getAdapter(); if (listadapter == null) return; int totalHeight = 0; for (int i = 0; i < listadapter.getCount(); i++) { View listItem = listadapter.getView(i, null, listview); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight();// getMeasuredHeight 获取View的实际高度 } ViewGroup.LayoutParams param = listview.getLayoutParams(); param.height = totalHeight + (listview.getDividerHeight() * (listadapter.getCount() - 1)); listview.setLayoutParams(param); } }
下一次:提供一个解决事件分发冲突的 解决办法。
相关文章推荐
- 【Android基础学习】动态设置 listView的高度,解决scrollView中嵌套listview时显示不全的问题
- ScrollView中嵌套ListView造成ListView高度只显示一行解决办法
- ScrollView嵌套ListView时ListView只显示出一行数据的解决办法
- 解决GridView,ListView嵌套在ScrollView时只显示一行高度的问题
- 解决ScrollView嵌套ListView,列表项高度不同,显示不全的问题
- 解决GridView,ListView嵌套在ScrollView时只显示一行高度的问题
- ScrollView嵌套listview、gradview等 嵌套式高度显示问题的解决办法
- 深入理解布局容器绘制,解决ListView嵌套listview,或者ScrollView嵌套listview,gridview的高度问题解决方法
- 解决ScrollView中嵌套ListView(本文为CornerListView)时显示异常的问题
- ListView(ScrollView)嵌套ListView、GridView显示不全,内容大于一行计算的高度不正确的解决办法
- android scrollview嵌套listview,高度异常问题解决
- android ScrollView中嵌套GridView,ListView只显示一行的解决办法
- ScrollView嵌套ListView时,ListView不能完全显示解决方法
- 解决ScrollView下嵌套ListView、GridView显示不全的问题(冲突)
- 【Android界面实现】解决ScrollView中嵌套Listview,Listview中嵌套Listview显示不完整和滑动冲突的问题
- 解决ScrollView下嵌套ListView、GridView显示不全的问题
- ScrollView中嵌套ListView是,嵌套在里面的ListView不能完全显示解决方法
- ScrollView中嵌套ListView是,嵌套在里面的ListView不能完全显示解决方法
- scrollview与listview、gridview嵌套高度冲突解决思路
- android ScrollView中嵌套GridView,ListView只显示一行的解决办法