问题
I have a normal NavigationDrawer with different fragments :
- News
- other Stuff 1
- other Stuff 2
- Setting
The problem :
The NewsFragment contains a SwipeRefreshLayout. It works great the first time I refresh.
I can change fragment to other Stuff 1 and 2 and Setting. So I come back to NewsFragment.
And now when I refresh, the fragment freezes.
The drawerLayout works correctly (open/close, even the ActionBar Title change) but the main fragment stay at NewsFragment and I can't scroll. But the scollListner works (I have log) but the view doesn"t change.
No refreshView (top of the swipeRefreshLayout), no scroll, no responding button (on focus, onclick) but only visually.
Actually, it's like a Responding Fragment is behind the frozen fragment.
Also I have this error in ADBLog :
SwipeRefreshLayout﹕ Got ACTION_MOVE event but don't have an active pointer id.
Any idea ??
I can post code if you ask.
回答1:
Ok I found the solution. I post it because it can happen to everybody and that's a little boring (two days to find for me).
First I had this in my XML which contains the SwipeRefreshLayout (a fragment):
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/news_container_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:background="@color/news_background">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/news_list_recycle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:dividerHeight="5dp" />
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/news_progress"
android:visibility="invisible"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
So, to fix the bug, YOU NEED TO JUST HAVE THE RECYCLEVIEW (or listview) IN YOUR SWIPEREFRESHLAYOUT :
So, I Move my progressBar and make the RelativeLayout as the rootView.
Result :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/news_progress"
android:visibility="invisible"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/news_container_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:background="@color/news_background">
<android.support.v7.widget.RecyclerView
android:id="@+id/news_list_recycle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:dividerHeight="5dp" />
</android.support.v4.widget.SwipeRefreshLayout>
I hope it will help someone else later.
回答2:
This answer worked for me. It's about clearing up the refresh layout in onPause().
回答3:
Your code example does indeed fix the issue. This seems to be a problem with the v21 support library.
For a little more clarification to help others that might come across this, the issue seems to be that the SwipeRefreshLayout
is no longer happy being the root view.
Adding a RelativeLayout
to wrap the SwipeRefreshLayout
fixes the bug in your case, rather than just having the ListView/RecyclerView
inside the SwipeRefreshLayout
. I've not tried, but I'm guessing a LinearLayout
or other would also fix things.
So the fix is:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- List, Layout etc -->
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
来源:https://stackoverflow.com/questions/26973679/swiperefreshlayout-got-action-move-freezes-view