Android TabHost Auto Scroll vertically in side ScrollView on TabChange?

后端 未结 2 1241
傲寒
傲寒 2021-01-07 12:50

I am using TabHost inside ScrollView in my Activity but when ever I select tab it automatically scrolls my view vertically to end.

2条回答
  •  轮回少年
    2021-01-07 13:33

    In this case child view getting focus due to that it get scrolled upward.

    for resolve this you need to create custom ScrollView that extend ScrollView. code snipt will look like this.

    public class MyScrollView extends ScrollView {
    
    
        public MyScrollView(Context context) {
            super(context);
    
        }
    
    
    
        public MyScrollView(Context context, AttributeSet attrs) {
            super(context, attrs);
    
        }
    
    
        @Override
        public void requestChildFocus(View child, View focused) {
           // if (focused instanceof TabHost)   // here 
                return;
            //super.requestChildFocus(child, focused);
    // here you need to return instead of **super.requestChildFocus(child, focused);**
        }
    

    and xml looks like this

      
    
    
    

提交回复
热议问题