SwipeRefreshLayout - swipe down to refresh but not move the view pull down

Jongz Puangput picture Jongz Puangput · Apr 28, 2014 · Viewed 35.5k times · Source

Is it possible ?? as a Title said

swipe down to refresh Layout but stick the Layout not move it down along swipe gusture

Thank you - I'm using SwipeRefreshLayout

Answer

Cabezas picture Cabezas · Sep 30, 2014

You try this way

listView.setOnScrollListener(new OnScrollListener() {

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}

@Override
public void onScroll(AbsListView view, int firstVisibleItem,
        int visibleItemCount, int totalItemCount) {
    boolean enable = false;
    if(listView != null && listView.getChildCount() > 0){
        // check if the first item of the list is visible
        boolean firstItemVisible = listView.getFirstVisiblePosition() == 0;
        // check if the top of the first item is visible
        boolean topOfFirstItemVisible = listView.getChildAt(0).getTop() == 0;
        // enabling or disabling the refresh layout
        enable = firstItemVisible && topOfFirstItemVisible;
    }
    swipeRefreshLayout.setEnabled(enable);
}});

This code doesn't work if listView has paddingTop