天天看点

ScrollView下嵌套GridView或ListView默认不在顶部的解决方法

当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

继续阅读