当ScrollView下嵌套GridView或ListView时。假设内容超过一屏默认位置不在ScrollView的顶部。用scrollViewMsg.scrollTo(0,0)设置也不起作用,这是由于嵌套GridView或ListView获了焦点,解决方法有例如以下几种:
方法1把ScrollView里的第一个View获取焦点:
baseView.setFocusable(true);
baseView.setFocusableInTouchMode(true);
baseView.requestFocus();
方法2把GrideView或ListView焦点禁用:
grid.setFocusable(false);
方法3重写ScrollView的方法:
@Override
protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) {
//禁止scrollView内布局变化后自己主动滚动
return 0;
}
QQ交流群:6399844