[英]How to hide part of content of the toolbar when using CoordinatorLayout
What I'm trying to achieve is to do some effect with collapsing toolbar. 我想要达到的目的是通过折叠工具栏实现某种效果。
I have a "title" that when collapsing toolbar is expanded, must be shown under the cross ( im1
), but collapsing is scrolled, the title must "move" to the next of the cross( im2
). 我有一个“标题”,当展开折叠工具栏时,必须显示在十字( im1
)下,但是滚动折叠时,标题必须“移动”到十字的下一个( im2
)。
I'm trying do this: 我正在尝试这样做:
<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>
What I've done is create a "custom toolbar" with the cross and the title. 我要做的是创建带有十字和标题的“自定义工具栏”。 And then add a another textview (with higher text, bolded..etc). 然后添加另一个textview(具有更高的文本,加粗..etc)。 But I don't know how to hide the toolbar title when is expanded. 但是我不知道在展开时如何隐藏工具栏标题。
Some real images: 一些真实的图像:
Not Collapsed (the textview of the toolbar must not be visible) 未折叠 (工具栏的textview不得可见)
if you want to do it with animation it requires a library if you want something similar without animation you just have to put the part you don't want to disappear inside the toolbar and the rest outside. 如果您想用动画来做,那么它需要一个库,如果您想要没有动画的类似东西,您只需要把不想消失的部分放在工具栏内,其余部分放在外面。
and in your code you can follow the state of the app bar and change the visibility accordingly 在代码中,您可以遵循应用栏的状态并相应地更改可见性
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.