android关于scrollview嵌套ExpandableListView的实现1
来源:互联网 发布:网络科学导论论文 编辑:程序博客网 时间:2024/05/22 15:09
public static void setListViewHeightBasedOnChildren(ListView listView) { //获取ListView对应的Adapter ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { return; } int totalHeight = 0; for (int i = 0, len = listAdapter.getCount(); i < len; i++) { //listAdapter.getCount()返回数据项的数目 View listItem = listAdapter.getView(i, null, listView); listItem.measure(0, 0); //计算子项View 的宽高 totalHeight += listItem.getMeasuredHeight(); //统计所有子项的总高度 } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); //listView.getDividerHeight()获取子项间分隔符占用的高度 //params.height最后得到整个ListView完整显示需要的高度 listView.setLayoutParams(params); }
计算出listview的高度 然后在代码中设置一下就行
我把参数ListView换成 ExpandableListView 发现到
ViewGroup.LayoutParams params = listView.getLayoutParams();这行params一直为null,以为adapter问题 然后修改 ExpandableListAdapter listAdapter = listView.getExpandableListAdapter();发现还是不行 看了下源码
listview继承自AbsListView而ExpandableListView继承自listview。看到这 这不是坑爹吗 这不都一样啊
研究一下之前的计算listview的高度的方法 很简单 拿到adapter 再拿到子view也就是每一项item的高度 计算有多少个 相乘在加上两个item之间的距离 so easy
那ExpandableListView怎么就不行 坑爹呢 这是 然后就发现getAdapter()这个 拿到适配器的这个实例 然后我们再看listview和expandblelistview的适配器
发现listview的适配器继承自BaseAdapter,同时BaseAdapter实现ListAdapter, SpinnerAdapter接口
而expandblelistview的适配器继承自BaseExpandableListAdapter,同时BaseExpandableListAdapter实现ExpandableListAdapter,HeterogeneousExpandableList接口
好吧 没往下研究了 水平有限 -。- 虽然两个adapter看似很多方法相同 但是确实不能用listview的方式来计算expandblelistview的高度 。。。百度好多都说这个方法可以 经确认完全不行的 有木有。。。
下篇进入正题
- android关于scrollview嵌套ExpandableListView的实现1
- android关于scrollview嵌套ExpandableListView的实现2
- android scrollview中嵌套expandablelistview
- android scrollview中嵌套expandablelistview
- android scrollview中嵌套expandablelistview
- ScrollView嵌套ExpandableListView,ExpandableListView的写法
- Scrollview嵌套ExpandableListView 的方法
- Android ScrollView嵌套ExpandableListView显示不正常的问题的解决办法
- Android ScrollView中嵌套ExpandableListView,item不显示的问题
- Android ScrollView嵌套listview或ExpandableListView
- android scrollview中嵌套expandablelistview高度问题
- Android ScrollView中嵌套ListView或ExpandableListView
- ScrollView嵌套ExpandableListView显示不正常的问题
- ScrollView嵌套 ExpandableListView
- Scrollview中嵌套Expandablelistview
- ScrollView中嵌套ExpandableListView
- Android中scrollview嵌套webview的实现
- [Android]ScrollView,ListView,ExpandableListView,ViewPager各种嵌套demo
- VC操纵EXCEL的两种方法
- MVC的理解
- 2.14 Displaying an Image on a Navigation Bar
- golang mysql 诊断之旅(2000万开房数据被曝光引发的血案)
- 面试中常见小而难的题
- android关于scrollview嵌套ExpandableListView的实现1
- java.lang.IncompatibleClassChangeError: class net.sf.cglib.core.DebuggingClassWriter has interface o
- Oracle WebLogic Server 与 Oracle Database 12c 的集成 (2)
- 文件上传 如何读取apk文件的 包名、版本号、图标?
- UITextField的圆角和常用样式
- Ubuntu12.04 64位安装Foxit Reader
- Navicat 数据模型
- 敏捷开发一千零一问系列之三十五:如何获取准确需求?(兼谈精益创业)
- android关于scrollview嵌套ExpandableListView的实现2