当显示小吃栏时,来自设计支持库的FAB不会向上移动

And*_*kov 4 android android-layout android-design-library

这篇文章说:

当你添加一个FloatingActionButton孩子作为你的孩子, CoordinatorLayout然后将其传递CoordinatorLayout给你的 Snackbar.make()电话 - 而不是显示在浮动动作按钮FloatingActionButton上的小吃店时,...当小吃店动画时自动向上移动并在小吃栏动画时返回到它的位置

我完全按照那里所描述的那样做,但FAB不会向上移动.(Snackbar可以刷掉,这意味着CoordinatorLayout知道它.)

UPD

布局:

<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>
Run Code Online (Sandbox Code Playgroud)

码:

mCoordinatorLayout = (CoordinatorLayout) findViewById(R.id.main_content);
...
Snackbar.make(mCoordinatorLayout, R.string.waypoint_deleted, Snackbar.LENGTH_LONG).show();
Run Code Online (Sandbox Code Playgroud)

aga*_*aga 7

我根据您发布的代码编写了示例项目,我必须更改三项内容才能FloatingActionButton了解相关内容Snackbar.

  1. 将我的构建的'minifyEnabled'属性设置为false- 看起来像Proguard剥离了一些Behaviour需要协调的注释(例如s)FloatingActionButton.您需要在启用了Proguard的发布版本中添加一些Proguard规则.
  2. FloatingActionButton作为第一个参数传递Snackbar.make(),而不是CoordinatorLayout这里提到的那样.
  3. 卸下app:layout_anchor="@id/action_toolbar"并更换app:layout_anchorGravity="bottom|right|end"app:layout_gravity="bottom|right|end"从布局(不知道是否适合你).

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