2017-06-07 4 views
0

私のアプリケーションは、下部に4つのタブを含むHomeActivityを中心に回転します。これらのタブはそれぞれフラグメントであり、すべてが最初から追加(置き換えられない)され、適切なタブをタップすると非表示/表示されます。NestedScrollViewのスクロール状態の保存

私の問題は、タブを変更するたびにスクロールの状態が失われることです。その問題を示す各フラグメントは、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> 

私は(例えばthis onethat one)インスタンスの状態を保存に関するいくつかの記事を読んで、そしてその解決策は私のシナリオでは動作しない、または私は4-12異なるフラグメントを持って与えられた実装するのは実用的ではないんどちらか私はそれを動作させるために変更する必要があります。

ネストされたスクロールビューにフラグメント変更のスクロール位置を保持させる最も良い方法は何ですか?

答えて

1

私がinthecheesefactoryに見つけた1つの解決策は、既定では、(EditTextの入力からスクロール位置までの)状態が保存されていますが、IDがxml要素に与えられている場合のみです。ちょうど私のNestedScrollViewにIDを追加私の場合は

は、問題修正:あなたは私の夕方保存

<?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:id="@+id/NestedScrollView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <!-- Content --> 

    </android.support.v4.widget.NestedScrollView> 

</LinearLayout> 
+0

を:) – ievgen

関連する問題