【问题标题】:Floating Action Button diasappears under SECOND Snackbar浮动操作按钮在 SECOND Snackbar 下消失
【发布时间】:2016-01-09 16:42:15
【问题描述】:

我正在使用 CoordinatorLayout 将浮动操作按钮保持在 Snackbar 上方,效果很好。 ...但仅适用于第一个 Snackbar。创建第二个时,当第一个仍然存在时,FAB 会滑到它下面。

我在 RecyclerView 中使用它,我可以在其中删除项目。当一个项目被删除时,会出现一个“撤消”Snackbar。因此,当您一个接一个地删除一些项目时,可见的 Snackbar 会被一个新的替换(这会导致 FAB 行为)

您知道将 FAB 保持在新 Snackbars 之上的解决方案吗?

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:fab="http://schemas.android.com/tools"
    android:id="@+id/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:backgroundTint="@color/background_grey"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical" />

    </LinearLayout>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_marginBottom="16dp"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            android:elevation="6dp"
            android:src="@drawable/ic_add_white_36dp"
            app:borderWidth="0dp"
            app:fabSize="normal"
            app:pressedTranslationZ="10dp"
            app:rippleColor="@color/abc_primary_text_material_dark" />

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

这是我删除项目后的样子

...然后在我删除另一个项目之后

【问题讨论】:

标签: android layout floating-action-button snackbar


【解决方案1】:

这总是会发生的,因为snackbar 是视图上方的一层。在这种情况下不应该使用堆叠的snackbar 请参阅google gidelines .. https://www.google.co.in/design/spec/components/snackbars-toasts.html#snackbars-toasts-usage

相反,您的实现应该类似于 https://github.com/jenzz/Android-UndoBar

为改变你的设计道歉

【讨论】:

  • 谢谢。我的 Snackbars 没有堆叠。当显示一个并且我从 RecyclerView 中删除另一个项目时,新的 Snackbar 会替换旧的。它看起来不像 Google 设计指南的屏幕截图 4。但是,在这种情况下,Snackbar(带有动作)不正是必需的吗?就像刷掉 Google Now Cards
  • 我在开头的帖子中附上了一些截图
  • 它实际上负责坐标布局来处理这个问题,每次出现snackbar时,但是在这种情况下会有一些错误..需要注意的重要一点是CoordinatorLayout没有任何对 FloatingActionButton 或 AppBarLayout 工作的先天理解——它只是以 Coordinator.Behavior 的形式提供了一个额外的 API,它允许子视图更好地控制触摸事件和手势,以及声明彼此之间的依赖关系并通过 onDependentViewChanged() 接收回调.你需要玩弄这两种方法..
  • 看看这个,可能会有所帮助......虽然 urs 是原生的,但仍然会覆盖该事件,将提供一些见解lab.getbase.com/introduction-to-coordinator-layout-on-android
猜你喜欢
  • 2015-12-13
  • 1970-01-01
  • 1970-01-01
  • 2019-06-02
  • 2015-10-23
  • 1970-01-01
  • 2015-10-26
  • 2020-01-03
  • 2021-08-21
相关资源
最近更新 更多