我有一个场景,其中一个Activity中的工具栏/操作栏具有与一般工具栏行为相反的行为。当片段中的motion layout向上滚动时它应该隐藏,并且当motion layout向下滚动时显示,这与一般滚动行为相反。
我完全隐藏了Support Action Bar和工具栏布局,但它没有任何动画并且没有好兆头,因为Activity包含一个BottomNavigation View,因此Action栏的常量隐藏和显示效果不佳。
supportActionBar?.hide()
containerToolbar.visibility = View.GONE
AppBarLayout.LayoutParams scroll-flags显然增加了一般行为。
fragment.xml
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:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/collapsing_header_arc"
app:showPaths="false"
android:background="@color/white"
tools:showPaths="true">
android:id="@+id/header"
android:layout_width="0dp"
android:layout_height="200dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shape_arc_height="26dp"
android:background="@color/yellow_dark"
app:shape_arc_position="bottom">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_actionbar_gradient" />
android:id="@+id/scrollview_counts_container2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:id="@+id/counts_container"
layout="@layout/layout_card_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:id="@+id/guideline_anchor"
android:layout_width="wrap_content"
android:layout_height="5dp"
android:orientation="horizontal"
android:background="@color/red_dark"
app:layout_constraintTop_toBottomOf="@id/header"/>
android:id="@+id/recyclerView"
android:layout_width="0dp"
android:layout_height="210dp"
app:layout_constraintBottom_toBottomOf="@+id/guideline_anchor"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline_anchor"
android:background="@color/btnRedAlpha" />
android:id="@+id/parent_parent_dashboard"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/recyclerView"
android:background="@color/transparent"
android:layout_marginTop="@dimen/marginNormal">
android:id="@+id/parent_dashboard"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:id="@+id/scrollview_counts_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/calendar_container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintVertical_bias="0.0"
android:nestedScrollingEnabled="true"
android:visibility="gone">
android:id="@+id/counts_container"
layout="@layout/layout_card_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"/>
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_margin="@dimen/marginBig"
app:layout_constraintTop_toBottomOf="@id/scrollview_counts_container"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_bias="0.0">
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="@color/yellow_dark" />
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_marginTop="@dimen/marginBig"
android:background="@color/yellow_dark"/>
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_marginTop="@dimen/marginBig"
android:background="@color/yellow_dark"/>
collapsing_header_arc.xml
xmlns:app="http://schemas.android.com/apk/res-auto">
app:constraintSetEnd="@id/end"
app:constraintSetStart="@id/start">
app:dragDirection="dragUp"
app:touchAnchorId="@id/guideline_anchor"
app:touchAnchorSide="top" />
android:id="@id/header"
android:layout_height="240dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
app:attributeName="arcHeightDp"
app:customFloatValue="60" />
android:id="@id/scrollview_counts_container2">
app:attributeName="visibility"
app:customStringValue="visible" />
android:id="@id/header"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
app:attributeName="arcHeightDp"
app:customFloatValue="0" />
android:id="@id/scrollview_counts_container2">
app:attributeName="visibility"
app:customStringValue="gone" />
有没有办法实现这个?