Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable touch events in SwipeRefreshLayout?

I use SwipeRefreshLayout by Google. and I have a few questions.

  1. how to block for touch screen at the time when it is active onRefresh()?
  2. how to make progress on the spinning center of the screen instead of the top, during the update?

    swipeLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipe_status_info);
    swipeLayout.setColorSchemeColors(Color.RED, Color.GREEN, Color.BLUE, Color.CYAN);
    swipeLayout.setOnRefreshListener(this);
    
    
    @Override
    public void onRefresh() {
        clearTable(holidayTable);
        clearTable(cityayTable);
        setData();
    }
    
like image 567
Valera Valerianov Avatar asked Dec 17 '14 07:12

Valera Valerianov


Video Answer


1 Answers

  1. If you want to block some view (blockedView) from getting a touch event during the refresh you can consume that event in the OnTouchListener:

    @Override
    public void onRefresh() {
        clearTable(holidayTable);
        clearTable(cityayTable);
        setData();
        refreshing = true;
    }
    ...
    
    blockedView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            //consuming the touch
            if (refreshing) return true;
            //letting the touch propagate
            else return false;
        }
    });
    
  2. set the desired offset in pixels using this method:

    swipeLayout.setProgressViewOffset(true, 0, offset);
    
like image 56
Alex Kuzmin Avatar answered Nov 03 '22 12:11

Alex Kuzmin