Scroll up does not work with SwipeRefreshLayout in Listview

后端 未结 10 1472
失恋的感觉
失恋的感觉 2020-12-01 10:36

I want to implement scroll to refresh functionality with a listView. Also there are other view elements in the same layout file which are displayed if the list is empty. Her

10条回答
  •  猫巷女王i
    2020-12-01 10:44

    I had a similar problem where the child of my SwipeRefreshLayout was a FrameLayout which had a TextView and ListView as children and when I scrolled up on the ListView it would try to do a refresh.

    I fixed it by using a custom FrameLayoutwhich overrides the canScrollVertically() method

    package com.wi.director.ui.common;

    import android.content.Context;
    import android.util.AttributeSet;
    import android.widget.FrameLayout;
    
    /**
     * Created by devansh on 9/22/15.
     */
    public class FrameLayoutForSwipeRefresh extends FrameLayout {
    
        public FrameLayoutForSwipeRefresh(Context context) {
            super(context);
        }
    
        public FrameLayoutForSwipeRefresh(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public FrameLayoutForSwipeRefresh(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }
    
        public boolean canScrollVertically(int direction) {
            if (super.canScrollVertically(direction)) {
                return true;
            }
    
            int cc = getChildCount();
            for (int i = 0; i < cc; i++) {
                if (getChildAt(i).canScrollVertically(direction)) {
                    return true;
                }
            }
    
            return false;
        }
    }
    

提交回复
热议问题