[英]FAB from design support library does not move upward when snackbar is shown
這篇文章說:
當您將一個
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>
碼:
mCoordinatorLayout = (CoordinatorLayout) findViewById(R.id.main_content);
...
Snackbar.make(mCoordinatorLayout, R.string.waypoint_deleted, Snackbar.LENGTH_LONG).show();
我根據您發布的代碼編寫了示例項目,我不得不更改三件事以使FloatingActionButton
了解Snackbar
。
false
- 看起來Proguard剝離了一些注釋(例如Behaviour
s),這些注釋是協調FloatingActionButton
所必需的。 您需要在啟用了Proguard的發布版本中添加一些Proguard規則。 FloatingActionButton
作為Snackbar.make()
的第一個參數傳遞,而不是像這里提到的CoordinatorLayout
本身。 app:layout_anchor="@id/action_toolbar"
並用app:layout_anchorGravity="bottom|right|end"
替換app:layout_anchorGravity="bottom|right|end"
app:layout_gravity="bottom|right|end"
布局(不確定它是否適合你)。 如果它不適合您,您可以嘗試編寫自己的Behavior
類,如上面提到的文章中所述。
我有一個類似的問題,我的fab按鈕不會向下移動。 花了一些時間,但這是因為我在開發者選項中有動畫。 希望你知道這個帖子有點過時了。
我遇到的問題是,在小吃店消失之后,晶圓廠不會回到原來的位置。 確保打開Animator持續時間刻度 。 一個好的默認值是1x。
設置可在以下位置找到:
在我的一個模擬器上關閉了此設置以及其他動畫設置。 重新打開它使工廠正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.