listview嵌入scrolview冲突解决方法
来源:互联网 发布:sql带参数的存储过程 编辑:程序博客网 时间:2024/06/06 16:25
在listview.setAdapter或者adapter.notifyDataSetChanged()之后,可以让不能完全显示的listview正确的显示在其父控件ScrollView中。需要注意的是,对于listview中的每个item的填充布局,布局的根必须是LinearLayout控件;否则,listview就不能通过onMeasure()正确的计算到每个item的高度并显示出来,并会抛出异常!
/** * 动态测量listview-Item的高度 * @param listView */public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { // pre-condition 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(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); }
/** * 设置不滚动 */ public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); }
0 0
- listview嵌入scrolview冲突解决方法
- Android 解决ScrolView嵌套GridView冲突问题
- ScrollView嵌入ViewPager 滑动冲突的解决方法
- ListView与ScrollView冲突解决方法
- ListView中点击冲突解决方法
- 解决scrolview 中含有listview问题
- ScrolView 嵌套ListView 显示不全的问题
- 关于ScrollView嵌入ListView,或ListView嵌入ListView,导致里层的ListView无法滑动解决方法。
- Android:ListView中嵌入GridView,处理点击事件的冲突
- MeasureSpecx学习(ScrollView中嵌入ListView,GridView冲突的解决)
- ScrollView和ListView套用冲突的解决方法
- 安卓中ScrollView和ListView冲突的解决方法
- Scrollview 嵌套Listview 冲突的解决方法
- ScrollView和ListView滚动手势冲突解决方法
- ScollView与ListView,GridView滑动冲突解决方法
- ListView与ScrollView的滑动冲突解决方法
- Fragment+ScrollView+ListView冲突各种解决方法
- ScrollView中嵌入ListView,GridView冲突的解决(让ListView全显示出来)
- uva 10954——Add All
- Generate Parentheses
- Android ListView 使用及MVC关系概要
- Django的单元测试
- 2015/11/5 笔记
- listview嵌入scrolview冲突解决方法
- 浅尝KMP算法
- 在linux上安装postgresql
- Linux源码中的mktime算法解析
- KMP算法的Next数组详解
- document.getElementById的用法
- newInstance参数详解
- 【poj2229】Sumsets
- UVa 12700 - Banglawash