FloatingActionButton 隐藏在列表滚动中 [英] FloatingActionButton hide on list scroll

查看:24
本文介绍了FloatingActionButton 隐藏在列表滚动中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 android.support.design.widget 包中的 FloatingActionButton:

Im using the FloatingActionButton from the android.support.design.widget package:

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_marginBottom="20dp"
    android:layout_marginEnd="16dp"
    android:clickable="true"
    android:backgroundTint="@color/primaryColor"
    android:src="@drawable/ic_search_white_24dp"
    app:borderWidth="0dp"
    app:elevation="6dp"
    app:backgroundTint="@color/primaryColorDark"
    app:rippleColor="@color/accentColor" />

是否可以将该按钮配置为在列表视图向下滚动时隐藏动画并在列表视图向上滚动到顶部时再次显示?

Is it possible to configure that button to hide with an animation when the listview is scrolling down and to show it again when listview is scrolling up to the top?

推荐答案

抱歉!我迟到了几年才能回答这个问题.我希望这仍然可以帮助某人.这也是我的第一个回答.

Sorry! I am late by years to answer this. I hope this still helps someone. This is also my first answer.

伙计们!无需实现滚动侦听器.

Mates! No need to implement scroll listeners.

在浮动操作按钮xml中添加以下内容:

Add the following to the floating action button xml:

app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior"

给予:

<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
        android:id="@+id/fabAddOItransferIn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:text="@string/btn_text_transfer_in"
        app:icon="@android:drawable/ic_input_add"
        app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

为了回应我的以下评论,"对不起!我只是注意到这有一个奇怪的副作用.如果添加了 app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior,任何小吃店都将与此浮动操作按钮重叠.☹️ 取消这条线将防止重叠,浮动操作按钮将按照它在协调器布局内的预期行为."

In response to the following comment of mine, "Sorry! I just noticed this has a weird side effect. Any snackbars will overlap this floating action button if app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior is added. ☹️ Taking this line off will prevent the overlap and the floating action button will behave as it is intended to inside the coordinator layout. "

要解决这个问题,请使用以下方法:

To counter this, do use the following:

Snackbar.make(floating_action_button, "Some snackbar text!", BaseTransientBottomBar.LENGTH_SHORT).setAnchorView(floating_action_button).show();

这篇关于FloatingActionButton 隐藏在列表滚动中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆