簡體   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