Android 工具栏折叠模式问题 [英] Android Toolbar collapseMode issue

查看:38
本文介绍了Android 工具栏折叠模式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,使带有标题文本的工具栏"在 CollapsingToolbarLayout 中向上滚动时不折叠.

I have an Issue making " toolbar with Title text " Not to Collapse while scrolling upwards in CollapsingToolbarLayout.

我尝试了一些调整,在我的 android.support.v7.widget.Toolbar 中使用 app:layout_collapseMode="none" 作为属性,但它不起作用.可能是我的布局有问题.

I have tried a few tweaks, by using app:layout_collapseMode="none" as attribute in my android.support.v7.widget.Toolbar but its not working. Maybe there is a problem with my layout.

以下是我想要实现的目标.

但是当我滚动到顶部时,Toolbar 也会崩溃,并且 tabBar 也会在里面滚动,变得不可见.下面是我现在所拥有的.

But when i scroll to the top, the Toolbar also collapse, and the tabBar also scrolls inside, and become non-visible. below is what i have now.

这是我的布局代码

<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.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">



        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="250dp"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.7">

                <ImageView
                    android:id="@+id/backdrop"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#20000000" />

            </FrameLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="none"
                >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Application Title"
                    android:textColor="#fff"
                    android:textSize="18sp" />
            </android.support.v7.widget.Toolbar>




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



        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|enterAlways">

            <android.support.design.widget.TabLayout
                android:id="@+id/detail_tabs"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                app:layout_collapseMode="pin"

                android:background="#00000000"
                app:tabSelectedTextColor="#3498db"
                app:tabTextColor="#000" />
            />

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

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

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#333"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>

依赖

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile "com.android.support:appcompat-v7:22.2.1"
    compile "com.android.support:support-annotations:22.2.1"
    compile "com.android.support:design:22.2.1"
    compile 'com.android.support:recyclerview-v7:22.2.1'
    compile 'com.android.support:cardview-v7:22.2.1'

}

推荐答案

试试这个...

您必须在 CollapsingToolbarLayout 中使用 app:layout_scrollFlags="scroll|exitUntilCollapsed" 而不是 app:layout_scrollFlags="scroll|enterAlways">

You have to use app:layout_scrollFlags="scroll|exitUntilCollapsed" instead of app:layout_scrollFlags="scroll|enterAlways" inside the CollapsingToolbarLayout

并在工具栏

<android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:contentScrim="?attr/colorPrimary" >

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="250dp"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.7" >

            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop" />

            <View
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#20000000" />
        </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" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Application Title"
                android:textColor="#fff"
                android:textSize="18sp" />
        </android.support.v7.widget.Toolbar>

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

这篇关于Android 工具栏折叠模式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆