SwipeRefreshLayout Got Action_Move freezes view

断了今生、忘了曾经 提交于 2019-12-05 13:30:13

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.

Bolling

This answer worked for me. It's about clearing up the refresh layout in onPause().

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