天天看點

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

繼續閱讀