When switch fragment with SwipeRefreshLayout during refreshing, fragment freezes but actually still work

后端 未结 8 1910
温柔的废话
温柔的废话 2020-11-28 04:31

UPDATE: I thought it worked correctly. But after some test trouble still exists *sniff*

Then I made a simpler version to see what exactly happen and

相关标签:
8条回答
  • 2020-11-28 04:53

    The solution works, but I think it is better just put those lines into its own function, like:

    public void terminateRefreshing() {
        mSwipeRefreshLayout.setRefreshing(false);
        mSwipeRefreshLayout.destroyDrawingCache();
        mSwipeRefreshLayout.clearAnimation();
    }
    

    and call when switching the fragment.

    Fragment prevFrag = fragmentManager.findFragmentById(drawerContainerId);
    
    if(prevFrag instanceof SwipeRefreshFragment) {
        ((SwipeRefreshFragment)prevFrag).terminateRefreshing();
    }
    
    fragmentManager.beginTransaction().replace(drawerContainerId, fragment).commit();
    
    0 讨论(0)
  • 2020-11-28 04:56

    This issue seems to still be occurring in appcompat 22.1.1. Wrapping the SwipeRefreshLayout inside a FrameLayout solved this for me

    <FrameLayout 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:id="@+id/contentView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/tweet_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/grey_300" />
    
    </android.support.v4.widget.SwipeRefreshLayout>
    </FrameLayout>
    
    0 讨论(0)
提交回复
热议问题