2016-03-25 16 views
2

Ich möchte Präferenzfragment mit Scroll-Aktivität wie Telegram-Anwendung haben. Ich benutzte einen android.support.v7.widget.RecyclerView in FrameLayout und dies ist meine Tätigkeit xml:PreferenceFragment mit CollapsingToolbarLayout

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layoutDirection="rtl" 
android:fitsSystemWindows="true"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/app_bar" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/app_bar_height" 
    android:fitsSystemWindows="true" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/toolbar_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     app:contentScrim="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:layout_collapseMode="pin" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.CollapsingToolbarLayout> 
</android.support.design.widget.AppBarLayout> 

<FrameLayout 
    android:id="@+id/conddd" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@android:id/list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 
</FrameLayout> 

Und das ist meine Aktivitätsklasse:

public class SettingsActivity extends AppCompatActivity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_settings); 
     getFragmentManager().beginTransaction() 
       .replace(R.id.conddd, new MyPreferenceFragment()) 
       .commit(); 
     if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
      getWindow().setNavigationBarColor(0xFF4095c2); 
     } 
    } 
} 

class MyPreferenceFragment extends PreferenceFragment { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     addPreferencesFromResource(R.xml.preferences); 
    } 
} 

Das Problem ist, wenn ich android.support.v7.widget.RecyclerView Toolbar don bin Scrollen 't collapse

Antwort

0

Ich habe es mit PreferenceFragmentCompat gelöst und es funktioniert super! aber für die Verwendung, dass Sie compile 'com.android.support:preference-v7:23.2.0'-build.gradle

0

Sie müssen auch die scrollflag-Tag der Symbolleiste geben.

Aktualisiert Layout-

<android.support.design.widget.AppBarLayout 
    android:id="@+id/app_bar" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/app_bar_height" 
    android:fitsSystemWindows="true" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/toolbar_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     app:contentScrim="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      app:layout_scrollFlags="scroll|enterAlways" 
      android:layout_height="?attr/actionBarSize" 
      app:layout_collapseMode="pin" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.CollapsingToolbarLayout> 
</android.support.design.widget.AppBarLayout> 

<FrameLayout 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@android:id/list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/bottom_sheet_behavior"/> 
</FrameLayout> 

Bitte nehmen Sie sich einen Blick zu. Weitere Referenz: Handling Scrolls

Update: Sie müssen den layout:behaviour Tag aus den recyclerview entfernen.

+0

hinzufügen müssen Ich denke, das liegt daran, dass die 'FrameLayout' nicht andere Widgets, aber ich kann abnehmen –

+0

Ist Ihre Mutter Layout CoordinatorLayout? –

+0

Im aktualisierten Layout haben Sie scrollFlag nicht an die Symbolleiste –

Verwandte Themen