繁体   English   中英

使用CoordinatorLayout时如何隐藏工具栏的一部分内容

[英]How to hide part of content of the toolbar when using CoordinatorLayout

我想要达到的目的是通过折叠工具栏实现某种效果。

在此处输入图片说明

我有一个“标题”,当展开折叠工具栏时,必须显示在十字( im1 )下,但是滚动折叠时,标题必须“移动”到十字的下一个( im2 )。

我正在尝试这样做:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/topic_choise_root_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/topic_choise_appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/topic_choise_collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white"
            app:contentScrim="@color/white"
            app:expandedTitleMarginStart="120dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <TextView
                android:id="@+id/topic_choise_collpasing_title"
                android:layout_width="match_parent"
                android:layout_height="128dp"
                android:layout_marginStart="16dp"
                android:layout_marginEnd="16dp"
                android:fontFamily="@font/montserrat_bold"
                android:gravity="bottom"
                android:lineSpacingExtra="8sp"
                android:textColor="@color/black"
                android:textSize="24sp"
                tools:text="¿Qué te gusta hacer?" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/topic_choise_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/white"
                app:layout_collapseMode="pin">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/ic_32_px_cross" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center_horizontal"
                        android:lineSpacingExtra="17sp"
                        android:text="What are you into?"
                        android:textColor="#253238"
                        android:textSize="15sp" />

                </LinearLayout>

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

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

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

我要做的是创建带有十字和标题的“自定义工具栏”。 然后添加另一个textview(具有更高的文本,加粗..etc)。 但是我不知道在展开时如何隐藏工具栏标题。

一些真实的图像:

未折叠 (工具栏的textview不得可见) 在此处输入图片说明

倒塌 在此处输入图片说明

如果您想用动画来做,那么它需要一个库,如果您想要没有动画的类似东西,您只需要把不想消失的部分放在工具栏内,其余部分放在外面。

在代码中,您可以遵循应用栏的状态并相应地更改可见性

appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
            @Override
            public void onStateChanged(AppBarLayout appBarLayout, State state) {

                if (state.name().equals("EXPANDED")) {


                } else if (state.name().equals("COLLAPSED")) {

                }
            }
        });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM