我正在尝试使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!