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




posted @ 2017-05-22 19:55  wzjhoutai  阅读(113)  评论(0编辑  收藏  举报