做开发是,需要scrollview嵌套listview,会出现listview显示不完全的问题,解决办法就是计算子元素高度,然后接着会出现进入页面scroll显示不在顶部问题
解决方法:
把scroll加上
bs_detail_scroll.smoothScrollTo(0,0);
然后在把listview取消焦点
reply_list.setFocusable(false);
ok!解决问题
public 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));
((MarginLayoutParams) params).setMargins(10, 10, 10, 10); // 可删除
listView.setLayoutParams(params);
}