ScrollView内嵌ListView(可滑动)导致滑动冲突的问题,表现为listView只能滑动几项,然而不能查看ListView的所有内容,例如图片下面 (列表很难滑动)
1,创建一个Util类(代码如下))
import android.view.View; import android.view.ViewGroup; import android.widget.ListAdapter; import android.widget.ListView; public class HeightOfListViewUtil { /** * scrollview嵌套listview显示不全解决 * * @param listView */ public static void setListViewHeightBasedOnChildren(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(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); } } 2.然后在Activity里面使用这个Util类里面的setListViewHeightBasedOnChildren()方法就好了。
使用后界面就变成这样了:
参考了下面博客的第二种方法。
https://blog.csdn.net/zhaokaiqiang1992/article/details/38585547?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.add_param_isCf&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.add_param_isCf