Android 如何在使用CoordinatorLayout时隐藏工具栏的部分内容
我试图实现的是通过折叠工具栏来实现一些效果 我有一个“标题”,当展开折叠工具栏时,它必须显示在十字(Android 如何在使用CoordinatorLayout时隐藏工具栏的部分内容,android,kotlin,visibility,android-collapsingtoolbarlayout,Android,Kotlin,Visibility,Android Collapsingtoolbarlayout,我试图实现的是通过折叠工具栏来实现一些效果 我有一个“标题”,当展开折叠工具栏时,它必须显示在十字(im1)下,但如果折叠被滚动,标题必须“移动”到下一个十字(im2) 我正在尝试这样做: <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/a
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>
崩溃了
如果要使用动画,则需要一个库
如果你想要一些没有动画的类似东西,你只需要把你不想消失的部分放在工具栏里面,其余的放在外面
在代码中,您可以跟踪应用程序栏的状态,并相应地更改可见性
appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
@Override
public void onStateChanged(AppBarLayout appBarLayout, State state) {
if (state.name().equals("EXPANDED")) {
} else if (state.name().equals("COLLAPSED")) {
}
}
});