AndroidScrollView与ListView的冲突问题
来源:互联网 发布:java else 必须 编辑:程序博客网 时间:2024/06/06 03:41
<ScrollView android:id="@+id/ScrollView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#ffffffff" android:scrollbars="vertical" > <LinearLayout android:id="@+id/tmall" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="文本备忘" android:textSize="28sp" /> <ListView android:id="@+id/listview0" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="智能备忘" android:textSize="28sp" /> <ListView android:id="@+id/listview1" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> </ScrollView>
public class ListViewUtils { public 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); }}
private void initView() { textListView = (ListView) findViewById(R.id.listview0); intelListView = (ListView) findViewById(R.id.listview1); textListView.setAdapter(new MyTestAdapter(this)); intelListView.setAdapter(new MyTestAdapter(this)); new ListViewUtils().setListViewHeightBasedOnChildren(textListView); new ListViewUtils().setListViewHeightBasedOnChildren(intelListView); }
0 0
- AndroidScrollView与ListView的冲突问题
- 安卓AndroidScrollView嵌套ListView的问题及其优化
- ScrollView与ListView的冲突问题
- ScrollView与ListView的冲突问题
- listview与onTouchEvent的冲突问题
- ScrollView与ListView冲突的问题
- ScrollView与listview的冲突问题汇总
- 完美解决ScrollView与ListView冲突问题(ListView与ListView的冲突)
- ListView与ScrollView冲突问题
- SwipeRefreshLayout与ListView冲突问题
- ScrollView与ListView冲突问题
- ListView的OnItemLongClickListener与PopupWindow显示冲突的问题
- ScrollView与ListView共存冲突保留ScrollView滚动的问题
- ListView(GridView)与ScrollView冲突的问题
- ViewPager与ListView纵向滑动冲突的问题
- Listview 与 Button和Text的焦点冲突问题~
- ScrollView与Listview嵌套使用时的滑动冲突问题
- 关于SwipeRefreshLayout 与listView 滑动冲突的问题
- 微服务产品级敏捷: 重新定义平台开发的需求管理
- Spark RDD缓存代码分析
- eclipse之SVN插件的中英文转换
- 初谈HTML
- 我是一个线程
- AndroidScrollView与ListView的冲突问题
- centos7+tomcat安装
- 三维散点图:Python 之matplotlib篇
- 索智的SC5806开发板的调试步骤V1.5去掉GooglePlay
- selenium webdriver 常用方法
- 数据泵导入报错ORA-39125和LPX-00225
- 跳过 google的开机向导 SetupWizard
- 142. Linked List Cycle II
- 从Android原生角度看移动html5开发APP(三)之上拉加载