【问题标题】:FAB from design support library does not move upward when snackbar is shown显示小吃店时,设计支持库中的 FAB 不会向上移动
【发布时间】:2015-11-15 10:58:34
【问题描述】:

This post 说:

当您将 FloatingActionButton 添加为您的孩子时 CoordinatorLayout 然后将 CoordinatorLayout 传递给您的 Snackbar.make() 呼叫 - 而不是显示在 浮动操作按钮,FloatingActionButton ... 自动 当小吃店动画进入并返回其位置时向上移动 当小吃店动画出来时

我已经完全按照那里的描述做了,但 FAB 没有向上移动。 (Snackbar可以刷出来,说明CoordinatorLayout知道。)

更新

布局:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.Toolbar
            android:id="@+id/action_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:theme="@style/ThemeOverlay.ActionBar"/>

        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/action_toolbar"/>

    </RelativeLayout>

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:layout_marginTop="?attr/actionBarSize"
        android:background="@color/theme_primary_darker_color"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"/>

</android.support.v4.widget.DrawerLayout>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/toolbar_action_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_navigation_white_24dp"
    android:layout_margin="16dp"
    android:visibility="gone"
    app:borderWidth="0dp"
    app:elevation="6dp"
    app:layout_anchor="@id/action_toolbar"
    app:layout_anchorGravity="bottom|right|end"
    app:pressedTranslationZ="12dp"/>

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

代码:

mCoordinatorLayout = (CoordinatorLayout) findViewById(R.id.main_content);
...
Snackbar.make(mCoordinatorLayout, R.string.waypoint_deleted, Snackbar.LENGTH_LONG).show();

【问题讨论】:

  • 请把你的布局和Activity的代码贴出来。
  • 好吧,不是完整的Activity,我是指你调用Snackbar.make()方法的地方。

标签: android android-layout android-design-library


【解决方案1】:

我已经根据您发布的代码编写了示例项目,我必须更改三件事以使 FloatingActionButton 知道 Snackbar

  1. 将我的构建的“minifyEnabled”属性设置为false - 看起来 Proguard 删除了一些注释(例如Behaviours),这些注释是协调FloatingActionButton 所必需的。您需要在启用 Proguard 的发布版本中添加一些 Proguard 规则。
  2. 传递FloatingActionButton 作为Snackbar.make() 的第一个参数,而不是here 提到的CoordinatorLayout 本身。
  3. 从布局中删除 app:layout_anchor="@id/action_toolbar" 并将 app:layout_anchorGravity="bottom|right|end" 替换为 app:layout_gravity="bottom|right|end"(不确定它是否适合您)。

如果它不适合你,你可以尝试编写自己的Behavior 类,如上文所述。

【讨论】:

  • 我收到Error:(84) No resource identifier found for attribute 'layout_gravity' in package 'com.mycompany.myapp
  • 而不是设置 minifyEnabled,您也可以将其添加到您的 proguard.flags 文件中:-keep class android.support.design.widget.FloatingActionButton$* { *; }
【解决方案2】:

我有一个类似的问题,我的 fab 按钮不会向下移动。花了我一段时间,但这是因为我在开发人员选项中关闭了动画。尽管我知道这篇文章有点过时,但希望你能成功。

【讨论】:

  • 这对我有用并不意味着它是唯一的答案。在我的情况下,这就是发生的事情
【解决方案3】:

我遇到了一个问题,即小吃店消失后工厂无法返回其原始位置。确保 Animator 持续时间比例 已打开。一个好的默认值是 1x。

设置可以在:

  1. 设置应用 --> 开发者选项
  2. 开发设置应用(在模拟器上)

此设置以及其他动画设置在我的一个模拟器上已关闭。重新打开它可以让晶圆厂正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-17
    • 2016-04-01
    • 2016-02-06
    • 2021-04-16
    • 1970-01-01
    • 2020-10-21
    • 2021-08-03
    • 2020-07-25
    相关资源
    最近更新 更多