我的应用程序围绕着一个HomeActivity,底部有4个选项卡。每个选项卡都是一个片段,它们从一开始就都被添加(而不是替换),并且在点击适当的选项卡时隐藏/显示。
我的问题是,每当我切换选项卡时,我的滚动状态就会丢失。出现此问题的每个片段都使用了android.support.v4.widget.NestedScrollView
(请参见下面的示例)。
注意:对于使用RecyclerView或ListView的片段,它们保留其滚动状态,原因未知。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/include_appbar_title" />
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Content -->
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
我阅读了几篇关于保存实例状态的文章(例如这篇和那篇),但它们的解决方案要么在我的情况下不起作用,要么不实用,因为我需要修改4-12个不同的片段才能使其工作。
如何让嵌套滚动视图保持其滚动位置,使其在片段更改时保持原样?