Scrolling funktioniert nicht mit CoordinatorLayout + Parallaxenbild + BottomSheetLayout
Ich habe eine Aktivität, die ein allgemeines Muster mit Parallaxenheaderbild und scrollendem Inhalt mithilfe von @ implementierCoordinatorLayout
, AppBarLayout
undCollapsingToolbarLayout
. Mein XML-Layout sieht folgendermaßen aus:
<android.support.design.widget.CoordinatorLayout
android:fitsSystemWindows="true"
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.design.widget.AppBarLayout
android:fitsSystemWindows="true"
android:id="@+id/appbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:fitsSystemWindows="true"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<TextView
android:background="@color/colorAccent"
android:gravity="center"
android:layout_height="250dp"
android:layout_width="match_parent"
android:text="ParallaxImage"
app:layout_collapseMode="paralla,x"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/content"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:layout_width="wrap_content"
android:text="@string/large_text"/>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Wie Sie in der folgenden GIF-Animation sehen können, funktioniert alles korrekt. Sie können den gesamten Bildschirm vom Inhalt scrollenNestedScrollView
sowie von derToolbar
oder die ParallaxeView
.
Google hat ein @ eingeführBottomSheetBehavior
class (Android Design Support Bibliothek 23.2) um Entwicklern bei der Implementierung von @ zu helfBodenbleche. Mein XML-Layout mit dem unteren Blatt sieht folgendermaßen aus:
<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:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<!-- ommited -->
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<!-- ommited -->
</android.support.v4.widget.NestedScrollView>
<LinearLayout
android:id="@+id/bottomSheet"
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="@android:color/holo_blue_bright"
android:orientation="vertical"
app:behavior_peekHeight="?attr/actionBarSize"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<TextView
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="BottomSheetLayout"
android:textColor="@android:color/white"/>
<android.support.v4.widget.NestedScrollView
android:id="@+id/bottomSheetContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="@android:color/holo_green_dark"
android:padding="16dp"
android:text="@string/large_text"
android:textColor="@android:color/white"/>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
Und das Ergebnis sieht so aus:
Wie Sie sehen können, kann ich jetzt nicht scrollen, wenn ich von der Parallaxe zu scrollen beginneView
. Scrollen von InhaltNestedScrollView
und vomToolbar
funktioniert wie erwartet.
Wie kann ich das Scrollen von der Parallaxe aus steuern?View
auch (wie in der ersten GIF-Animation)? Es scheint, dass dasBottomSheetBehavior
fängt Berührungsereignisse ab und verhindert, dassAppBarLayout (AppBarLayoutBehavior)
, um die Schriftrolle zu handhaben. Aber das Seltsame ist, dass das Scrollen vonToolbar
Works und beide ParallaxeView
undToolbar
sind Kinder desAppBarLayout
.