android – 滚动感知FAB隐藏,但后来不再出现

前端之家收集整理的这篇文章主要介绍了android – 滚动感知FAB隐藏,但后来不再出现前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我制作了一个带有recyclerview和浮动动作按钮的 Android应用程序.向下滚动时,按钮应隐藏,向上滚动时应再次显示.我用 this tutorial来实现这个行为.

结果是,当我向下滚动时FAB隐藏,但是当向上滚动时它不会再次出现:(类ScrollAwareFABBehavior与教程相同.但我使用的是嵌套布局.

这是我的布局(recyclerview位于content_main的LinearLayout中):

<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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="org.myorganisation.mypackage.someActivity">

    <include layout="@layout/toolbar" />

    <include layout="@layout/content_main" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/add_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/plus"
        app:layout_behavior="org.myorganisation.mypackage.someActivity.helpers.ScrollAwareFABBehavior" />

    <LinearLayout
        android:id="@+id/insert_alert"
        android:layout_width="wrap_content"
        android:layout_height="50sp"
        android:layout_margin="@dimen/fab_margin"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:paddingEnd="70sp"
        android:visibility="gone"
        app:layout_anchor="@id/add_fab"
        app:layout_anchorGravity="bottom|left">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:text="@string/initial_alert"
            android:textColor="@color/colorPrimaryDark"
            android:textStyle="bold|italic" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_keyboard_arrow_right_black_24sp"
            android:tint="@color/colorPrimary" />
    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>

解决方法

支持库的25.1.0版开始,隐藏视图不再按照 this bug滚动事件.

comment #5所述:

This is working as intended,your dependency chain is the wrong way. Your RecyclerView (Behavior) should be triggering the FAB visibility change.

猜你在找的Android相关文章