SwiperefreshLayout in Android

后端 未结 7 2119
半阙折子戏
半阙折子戏 2020-12-09 03:58

i am using SwipeRefreshLayout in my below layout:




        
相关标签:
7条回答
  • 2020-12-09 04:51

    Ok I have got it working. If the SwipeRefreshLayout is the root of the layout and the ScrollView resides deep into the hierarchy (I had put the ScrollView inside a RelativeLayout) and not the direct child of the SwipeRefreshLayout, it won’t detect a swipe up on the ScrollView properly.

    You should create a custom class that extends SwipeRefreshLayout and override canChildScrollUp() method in SwipRefreshLayout

    Here is a example :

     public class CustomSwipeRefreshLayout extends SwipeRefreshLayout {
    
        private ScrollView scrollview;
    
        public CustomSwipeRefreshLayout(Context context) {
            super(context);
        }
    
        public CustomSwipeRefreshLayout(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public void setView(ScrollView view) {
            this.scrollview = view;
        }
    
        @Override
        public boolean canChildScrollUp() {
            return scrollview.getScrollY() != 0;
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题