android向上滚动效果显示标题,Android:向上滚动时显示工具栏(向上拖动),向下滚动时隐藏(向下拖动)(示例代码)...

我有一个场景,其中一个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" />

有没有办法实现这个?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值