android - CollapsingToolbarLayout 内的 ViewPager

标签 android android-layout android-viewpager android-collapsingtoolbarlayout

我的应用程序中有一个 collapsingToolbarLayout。我在我的布局顶部放置了一个 ViewPager。我希望我的工具栏在展开状态下消失,并在折叠状态下固定。我为布局编写了这段代码,但是当我滚动布局时,toolbar 没有出现,而是出现了 ViewPager 的部分。

 <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    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_height="192dp"
        android:layout_width="match_parent"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="@android:color/transparent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:layout_scrollInterpolator="@android:anim/decelerate_interpolator"
            app:toolbarId="@+id/toolbar"
            android:fitsSystemWindows="true">

            <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="200dp"
            >

            <android.support.v4.view.ViewPager
            android:id="@+id/slider"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_collapseMode="parallax"
            ></android.support.v4.view.ViewPager>

            <me.relex.circleindicator.CircleIndicator
            android:id="@+id/Indicator"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_gravity="center"
            android:layout_marginTop="10dp" />
            </FrameLayout>


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

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


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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <TextView
                android:id="@+id/txtTitleCategory"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/category_title"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="30dp"
                android:layout_marginEnd="20dp"/>
            <android.support.v7.widget.RecyclerView
                android:id="@+id/categoryRecy"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txtTitleCategory"
                android:layout_margin="20dp"/>
            <TextView
                android:id="@+id/txtTopCourseCat1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="دوره های محبوب"
                android:layout_below="@+id/categoryRecy"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="30dp"
                android:layout_marginEnd="20dp"
                />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/temp"
                android:layout_below="@+id/topCourseCat1Recy"/>
            <android.support.v7.widget.RecyclerView
                android:id="@+id/topCourseCat1Recy"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txtTopCourseCat1">

            </android.support.v7.widget.RecyclerView>

        </RelativeLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

这是我的应用程序的屏幕截图: Expended State Collapsing State

这是我预期行为的屏幕截图: Expended State Collapsing State

最佳答案

像这样改变工具栏

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    app:layout_collapseMode="pin"
    android:background="@color/colorPrimary"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

谢谢

关于android - CollapsingToolbarLayout 内的 ViewPager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54436020/

相关文章:

android - 如何在android项目的每个 Activity 中调用一个函数?

android - 如何将我的 Firebase 实时数据库传输到 Firebase Cloud Firestore

安卓工作室 : Link of external JAR in a multi modules project

android - getChildFragmentManager > beginTransaction > 替换 > 提交 : no result

viewpager 中的 Android 双指缩放布局,左右填充

android - 为每部手机自动更新 vcard

Android如何在软键盘可见时在全屏模式下调整布局

Android:强制横向但允许旋转

java - 使用 match_parent 为什么文本位于右侧 View 下方?

android - 扩展 viewpager 以包含导航指示器