gpt4 book ai didi

android - CoordinatorLayout 内的 Viewpager 不滚动折叠工具栏

转载 作者:太空宇宙 更新时间:2023-11-03 11:46:44 26 4
gpt4 key购买 nike

我正在尝试为我的布局实现视差效果。它有效,但我还需要一件事。这是我的代码

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator_layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_main"
android:layout_width="match_parent"
android:layout_height="@dimen/height_toolbar_header_experiment_result"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:titleEnabled="false">

<ImageView
android:id="@+id/image_view_tab_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/experiment_result_header"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>

<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.3"
android:background="@android:color/black"
android:fitsSystemWindows="true"/>

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_tab_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="top"
android:layout_marginBottom="?actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

<android.support.design.widget.TabLayout
android:id="@+id/tab_layout_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:tabIndicatorColor="@android:color/white"
app:tabSelectedTextColor="@android:color/white"
app:tabTextColor="@color/whitesmoke"/>

</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
android:id="@+id/view_pager_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</android.support.design.widget.CoordinatorLayout>

这很好用,但是我只能在滑动标题 ImageView (image_view_tab_header) 时滚动/折叠工具。当我尝试在 ViewPager 内向上滑动时,它不会折叠工具栏。仅当我尝试在页眉内部向上滑动时。

在 viewpager 内滑动时如何启用工具栏折叠?

谢谢

最佳答案

通过在 NestedScrollView 中包含 ViewPager 来尝试以下操作

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v4.view.ViewPager
android:id="@+id/view_pager_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.v4.widget.NestedScrollView>

关于android - CoordinatorLayout 内的 Viewpager 不滚动折叠工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47070344/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com