Gibt es eine Möglichkeit, ein AppBarLayout in einen ViewPager zu setzen und das Scrollverhalten zu aktivieren? Hintergrund ist, dass ich eine Kopfzeile auf dem ersten Fragment haben möchte, das aus dem Bildschirm scrollt, wenn der Benutzer herunterscrollt. Alle anderen Fragmente im ViewPager haben keinen Header. Meine Bemühungen sind bisher nicht erfolgreich, weil der Header nicht scrollt. Außerhalb des ViewPagers funktioniert das Scrollen einwandfrei.AppBarLayout innerhalb des ViewPagers mit Scrolling-Verhalten
Ich schätze Ihre Hilfe.
Aktivität Layout:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:orientation="vertical">
<include layout="@layout/toolbar"/>
<include layout="@layout/toolbar_shadow"/>
</LinearLayout>
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/navigation_header"
app:menu="@menu/navigation_menu"/>
</android.support.v4.widget.DrawerLayout>
Fragment Layout:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/space_between_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
app:elevation="0dp">
<!-- HEADER -->
<RelativeLayout
android:id="@+id/header_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed">
<include layout="@layout/journal_header" />
</RelativeLayout>
</android.support.design.widget.AppBarLayout>
<com.github.clans.fab.FloatingActionMenu
android:id="@+id/button_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_add_white_24dp"
app:layout_behavior="de.malnvenshorn.slimly.ui.component.ScrollingBehaviorFAB">
<com.github.clans.fab.FloatingActionButton
android:id="@+id/button_add_food"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_restaurant_menu_white_24dp"
fab:fab_size="mini"/>
<com.github.clans.fab.FloatingActionButton
android:id="@+id/button_add_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_directions_bike_white_24dp"
fab:fab_size="mini"/>
</com.github.clans.fab.FloatingActionMenu>
</android.support.design.widget.CoordinatorLayout>