我有一个简单的应用程序,其中包含具有两个片段(FragmentA和FragmentB)的活动(充当主机活动)。
FragmentA中有一个SwipeRefreshLayout。当SwipeRefreshLayout刷新时,我们用FragmentB替换FragmentA。如果我们返回到FragmentA(通过按back按钮),SwipeRefreshLayout将消失。为了理解我的意思,请看下面的图片:

如何防止SwipeRefreshLayout在替换碎片后消失?我的类非常简单,我只是用FragmentB替换了FragmentA
fragment_a.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/click"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me!"
android:layout_gravity="center"/>
</FrameLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>发布于 2019-06-21 23:19:06
相反,您应该在活动的xml文件中使用您的SwipeFreshLayout,该文件是两个片段的父文件。
https://stackoverflow.com/questions/56705708
复制相似问题