使用ViewPager的CollapsingToolbarLayout [英] CollapsingToolbarLayout with a ViewPager
本文介绍了使用ViewPager的CollapsingToolbarLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用CollapsingToolbarLayout具有可折叠的工具栏,该工具栏的ViewPager在向上滚动时会逐渐消失,但是如果存在ViewPager,我似乎会失去向上滚动的能力.
I'm trying to use the CollapsingToolbarLayout to have a collapsible toolbar with a ViewPager that fades away while scrolling up but I seem to lose the ability to scroll up if the ViewPager is present.
ViewPager应该在工具栏中显示多个图像.
The ViewPager is supposed to show multiple images in the Toolbar.
这是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>
推荐答案
我设法通过将ViewPager的高度设置为固定大小来解决此问题.看来wrap_content
并不取决于图像的大小.
I managed to fix this by setting the ViewPager's height to a fixed size. It seems that wrap_content
doesn't regardless of the image size.
这篇关于使用ViewPager的CollapsingToolbarLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文