南京电商网站开发,网片点焊机,广州番禺职业技术学院门户网站,电子商务网站建设客户需求调查表问题#xff1a;
当ScrollView嵌套ListView时#xff0c;ListView的高度设置为wrap_content时出现ListView的高度不能完全展开#xff0c;而只显示的第一个Item。 解决方法#xff1a;
按item的个数乘以高度计算出listview的总高度#xff0c;并在数据变化时直接设置lis…问题
当ScrollView嵌套ListView时ListView的高度设置为wrap_content时出现ListView的高度不能完全展开而只显示的第一个Item。 解决方法
按item的个数乘以高度计算出listview的总高度并在数据变化时直接设置listview高度保证完全显示。
具体如下
1、计算高度 private int getListViewHeight(ListView listView){ListAdapter listAdapter listView.getAdapter();if(listAdapternull)return 0;int totalHeight 0;int itemHeight 0;int count listAdapter.getCount();for(int i0;icount;i){View itemView listAdapter.getView(i,null,listView);itemView.measure(0,0);itemHeight itemView.getMeasuredHeight();totalHeight itemView.getMeasuredHeight();}int dividerHeight listView.getDividerHeight() * (count-1);int itemHeight_1 listView.getResources().getDimensionPixelSize(R.dimen.gnss_item_height);int re itemHeight_1 * (count6);return re;//(totalHeight dividerHeight);}
2、动态设置控件高度 ViewGroup.LayoutParams params listView.getLayoutParams();params.height getListViewHeight(listView);listView.setLayoutParams(params);
问题解决。 参考链接
https://blog.51cto.com/u_16175497/9499844