SwipeRefreshLayout gesture detection in drawer

风格不统一 提交于 2020-01-03 00:52:29

问题


I'm using SwipeRefreshLayout in drawer. When I stat scrolling up and down in the listview the gesture should be straight up and down, If the finger moves just a little bit a side without lifting it up, the scroll gesture stops and starts the gesture for open close the drawer. If I'm not using SwipeRefreshLayout, the scroll gesture dose not stops until I lift my finger up.

This is the layout:

<android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_to_refresh_lisview_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical"
        tools:ignore="NestedWeights" >

        <views.IndexableListView
            android:id="@+id/listview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#FFFFFF" />
    </android.support.v4.widget.SwipeRefreshLayout>

The code is the same as this one: http://antonioleiva.com/swiperefreshlayout/


回答1:


I had the same problem. You have to "lock" the drawer while you are scrolling and unlock it again when the scrolling even finish. For that I used 2 things:

  1. add an OnScrollListener to your listView like:

    mDrawerListView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {
            if (i == SCROLL_STATE_IDLE)
                mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
            else
                mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
        }
    
        @Override
        public void onScroll(AbsListView absListView, int i, int i2, int i3) {
    
        }
    });
    
  2. To avoid some problems trying to fire "refresh event", you should implement the work around suggested by spencer on this link: Issue 69074



来源:https://stackoverflow.com/questions/25643473/swiperefreshlayout-gesture-detection-in-drawer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!