ScrollView自动上滑问题解决办法
-
grid.setFocusable(false)
-
update数据后,手动scrollto(0,0)
-
重写ScrollView中的computeScrollDeltaToGetChildRectOnScreen,让该方法返回0
ListView只显示一项解决办法
/** * 动态设置ListView的高度,由于ScrollView套ListView问题,必须这样做 * * @param listView */ public static void setListViewHeightBasedOnChildren(ListView listView) {
if (listView == null) return;
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
// pre-condition
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);
}