android中scrollview中嵌入listview 产生的滚动问题
来源:互联网 发布:java中的file类 编辑:程序博客网 时间:2024/06/04 17:43
android中使用ScrollView内嵌ListView共存会存在滚动的问题,并且ListView只显示一个半Item。
当ListView的高度设定一定的值时,ListView同样地会显示对应的高度的Item。
因此我们可以计算出这个ListView的总高度,再将它设置到ListView中,这样就解决了之前的问题。
代码如下:
public void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter adapter = listView.getAdapter(); if (adapter == null) { return null; } int height = 0; for (int i = 0; i < adapter.getCount(); i++) { View v = adapter.getView(i, null, listView); v.measure(0, 0); height += v.getMeasuredHeight(); } ViewGroup.LayoutParams ps = listView.getLayoutParams(); ps.height = height + (listView.getDividerHeight() * (adapter.getCount() - 1)); ((MarginLayoutParams)ps).setMargins(15, 15, 15, 15); listView.setLayoutParams(ps); }其中xml布局如下:<ScrollViewxmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fadingEdge = "none" > <LinearLayout android:gravity="center_horizontal" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ListView android:id="@+id/listView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:dividerHeight="0.0dip" android:fadingEdge="none" /> </LinearLayout></ScrollView>
0 0
- android中scrollview中嵌入listview 产生的滚动问题
- ListView嵌入ScrollView中出现的问题及解决方法
- scrollView中嵌套ListView,ListView不能滚动的问题
- android中ScrollView如何嵌入ListView
- ListView、ScrollView中嵌套的EditText不能滚动的问题
- android中scrollview嵌套listview的问题
- Android 设置listview在scrollView中不滚动的方法
- Android 中listview 和scrollview 滚动冲突事件的解决方法
- scrollview中嵌入listview动态计算listview的高度
- Android ListView中嵌套ScrollView,ScrollView不能滚动
- 关于Android中ScrollView嵌入ListView重写OnMeasure后ListView在顶端的解决方法
- ScrollView 中嵌入ListView 控件 滑动ListView
- android开发中ScrollView中嵌套ListView造成ListView无法独立滚动的解决方法
- ScrollView中嵌入Listview,当item高度不一样的时候,item展示不全问题
- Android 设置ListView不可滚动 及在ScrollView中不可滚动的设置
- ScrollView中如何嵌入ListView只显示一条的解决办法
- MeasureSpecx学习(ScrollView中嵌入ListView,GridView冲突的解决)
- 解决ScrollView中嵌套ListView或GridView导致的ScrollView自动滚动到ListView或GridView位置的问题
- Python的TkinterButton做为父窗口
- .NET技术网站群系统介绍
- Python-Tkinter的Entry详解
- Python做的眼睛护士
- Tkinter隐藏窗口再让他显示出来的例子
- android中scrollview中嵌入listview 产生的滚动问题
- Python的Lambda表达式
- 关于杨辉三角的,有一个错误,找不到,帮忙看一下啊
- UIAlertView 动画,有了这些源码,就可以随意写一个AlerView出来了
- Python的Tkinter将窗口置顶
- Python眼睛护士改进版
- MySql命令行基本操作
- MySQLdb 连接Mysql 数据库出错解决
- Python使用MySQLdb操作MySQL