Recyclerviews and SwipeRefreshLayout using support library 23.2.0

前端 未结 3 1476
暖寄归人
暖寄归人 2021-01-05 12:39

Has anyone figured out a way to get recyclerviews, AppbarLayouts and SwipeRefreshLayout to work together on 23.2 yet? I am using a pretty standard method I think, but the sw

3条回答
  •  长发绾君心
    2021-01-05 13:19

    attrs.xml

    
    
        
            
        
    
    

    layout.xml

    
    
        
    
            
    
            
        
    
    
    

    ImprovedSwipeLayout.java

    public class ImprovedSwipeLayout extends SwipeRefreshLayout {
    
        private static final String TAG = ImprovedSwipeLayout.class.getCanonicalName();
        private int mScrollableChildId;
        private View mScrollableChild;
    
        public ImprovedSwipeLayout(Context context) {
            this(context, null);
        }
    
        public ImprovedSwipeLayout(Context context, AttributeSet attrs) {
            super(context, attrs);
    
            TypedArray a = context.obtainStyledAttributes(
                    attrs, R.styleable.ImprovedSwipeLayoutAttrs);
            mScrollableChildId = a.getResourceId(R.styleable.ImprovedSwipeLayoutAttrs_scrollableChildId, 0);
            mScrollableChild = findViewById(mScrollableChildId);
            a.recycle();
        }
    
        @Override
        public boolean canChildScrollUp() {
            ensureScrollableChild();
    
            if (android.os.Build.VERSION.SDK_INT < 14) {
                if (mScrollableChild instanceof AbsListView) {
                    final AbsListView absListView = (AbsListView) mScrollableChild;
                    return absListView.getChildCount() > 0
                            && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                            .getTop() < absListView.getPaddingTop());
                } else {
                    return mScrollableChild.getScrollY() > 0;
                }
            } else {
                return ViewCompat.canScrollVertically(mScrollableChild, -1);
            }
        }
    
        private void ensureScrollableChild() {
            if (mScrollableChild == null) {
                mScrollableChild = findViewById(mScrollableChildId);
            }
        }
    
    }
    

    It's from http://nerd-is.in/2014-09/add-multi-child-view-in-swiperefreshlayout/

    Create a View extend SwipeRefreshLayout and custom canChildScrollUp.

提交回复
热议问题