Android SwipeRefreshLayout与ListView、ScrollView滑动兼容冲突

public class CustomSwipeRefreshLayout extends SwipeRefreshLayout {

    AbsListView mAbsListView;
    ScrollView mScrollView;
    int type = 0;

    public CustomSwipeRefreshLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    /**  * RecyclerView未有冲突,建议使用  * @param listView  */  public void setResolveListView(AbsListView listView) {
        this.mAbsListView = listView;
        type = 1;
    }

    public void setResolveScrollView(ScrollView scrollView) {
        this.mScrollView = scrollView;
        type = 2;
    }

    @Override
    public boolean canChildScrollUp() {
        switch (type) {
            case 1://ListView
                if (mAbsListView != null && mAbsListView instanceof AbsListView&&mAbsListView.getVisibility()==VISIBLE) {
                    return mAbsListView.getChildCount() > 0 && (mAbsListView.getFirstVisiblePosition() > 0 || mAbsListView.getChildAt(0).getTop() < mAbsListView.getPaddingTop());
                }
            case 2://ScrollView
                if (mScrollView != null&&mScrollView.getVisibility()==VISIBLE) {
                    return mScrollView.getScrollY()>0;
                }
                break;
        }
        return super.canChildScrollUp();
    }
 使用说明:
 与常规swipeRefreshLayout使用方式一样。
需要说明的:
调用
setResolveListView、
setResolveScrollView,
调用你需要解决冲突的控件

你可能感兴趣的:(Android SwipeRefreshLayout与ListView、ScrollView滑动兼容冲突)