簡體   English   中英

為什么我的 FAB animation 會出現 Material BottomAppBar 的屏幕?

[英]why is my FAB animation going out of screen with Material BottomAppBar?

所以我得到了這個工作,它很棒

在此處輸入圖像描述

然后我嘗試在右側設置父FAB:

binding.bottomAppBar.fabAlignmentMode = BottomAppBar.FAB_ALIGNMENT_MODE_END

它可以工作,但現在父 FAB animation 退出屏幕。

在此處輸入圖像描述

下面是對正在發生的事情的更好了解:

在此處輸入圖像描述

打開 animation:

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<rotate
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="45"
    android:duration="300" />

關閉 Animation:

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<rotate
    android:fromDegrees="45"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="0"
    android:duration="300"
    />

活動 XML:

    <androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottomAppBar"
        android:layout_gravity="bottom"
        style="@style/Widget.MaterialComponents.BottomAppBar.Colored"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:fabAlignmentMode="end"/>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/addFav"
        app:layout_anchor="@id/bottomAppBar"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

我怎樣才能解決這個問題? 子 FAB 動畫按預期工作。

這是正在發生的事情。

  1. 當 XML 充氣時,FAB 位於中心。 所以pivotX現在是屏幕的中心。
  2. 您在膨脹后以編程方式在 Java/Kotlin 中設置fabAlignmentMode
  3. 當旋轉開始時, pivotX仍然使用膨脹點的值,因此使用舊值。
  4. FAB 圍繞其先前位置的中心旋轉,因此離開屏幕。 請注意第二個 GIF 中 FAB 的運動曲線。

使用 fabAlignmentMode 在 XML 中設置fabAlignmentMode應該可以解決您的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM