问题
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:
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) { } });
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