CollapsingToolbarLayout with ViewPager

I'm trying to use CollapsingToolbarLayout to have a collapsible toolbar with a ViewPager that disappears while scrolling, but I seem to lose the ability to scroll up if a ViewPager is present.

The ViewPager is supposed to display several images in the Toolbar.

Here's the XML:

<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/app_bar_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" android:fitsSystemWindows="true"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_scrollFlags="scroll|exitUntilCollapsed" app:contentScrim="?attr/colorPrimary" android:fitsSystemWindows="true"> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_collapseMode="parallax" android:fitsSystemWindows="true"> </android.support.v4.view.ViewPager> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" app:layout_collapseMode="pin" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.NestedScrollView android:id="@+id/scroll" android:layout_width="match_parent" android:layout_height="match_parent" android:clipToPadding="false" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <!-- Content --> </android.support.v4.widget.NestedScrollView> </android.support.design.widget.CoordinatorLayout> 
+5
source share
1 answer

I managed to fix this by setting the height of the ViewPager to a fixed size. It seems that wrap_content is independent of image size.

+5
source

All Articles