简体   繁体   English

Android浮动操作按钮未重置位置

[英]Android Floating Action Button not resetting position

Using the 23.3.0 version of the support libraries and testing on Android M. And having issues with a FAB repositioning itself after a Snackbar is shown. 使用23.3.0版本的支持库并在Android M上进行测试。在显示Snackbar后,FAB重新定位问题。

The fab correctly moves up when a Snackbar is shown, however it does not move down when the Snackbar dismisses itself. 当一个Snackbar被显示时,fab正确地向上移动,但是当Snackbar解散时它不会向下移动。

Code: 码:

Snackbar.make(coordinatorLayout, R.string.msg_add_team,     Snackbar.LENGTH_LONG).show();

Also tried to use the callback functionality of the Snackbar to force the position back on dismiss, this breaks subsequent displays of the Snackbar as it will no longer move the fab out of the way. 还尝试使用Snackbar的回调功能强制关闭位置,这打破了Snackbar的后续显示,因为它将不再移动工厂。

Code for callback: 回调代码:

@Override
public void onDismissed(Snackbar snackbar, int event) {
    super.onDismissed(snackbar, event);                       
    newGameFab.setTranslationY(0); 
}

Layout: 布局:

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

<android.support.design.widget.FloatingActionButton
    android:id="@+id/new_game"
    android:layout_width="56dp"
    android:layout_height="56dp"
    android:src="@drawable/ic_add_white_24dp"
    android:layout_gravity="bottom|end"
    app:elevation="6dp"
    app:pressedTranslationZ="12dp"
    android:layout_marginBottom="@dimen/fab_margin_bottom"
    android:layout_marginRight="@dimen/fab_margin_right"
    app:borderWidth="0dp"
    app:backgroundTint="@color/accent"/>

wrap your View containing floating action button with a CoordinatorLayout like this: 使用CoordinatorLayout包含包含浮动操作按钮的View,如下所示:

<android.support.design.widget.CoordinatorLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/coordinatorLayout">

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/new_game"
        android:layout_width="56dp"
        android:layout_height="56dp"
        android:src="@drawable/ic_add_white_24dp"
        android:layout_gravity="bottom|end"
        app:elevation="6dp"
        app:pressedTranslationZ="12dp"
        android:layout_marginBottom="@dimen/fab_margin_bottom"
        android:layout_marginRight="@dimen/fab_margin_right"
        app:borderWidth="0dp"
        app:backgroundTint="@color/accent"/>
</android.support.design.widget.CoordinatorLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM