簡體   English   中英

如何在使用 BottomNavigationView 和導航組件導航到同一片段時實現不同的 animation?

[英]How to achieve different animation while navigating to the same fragment with BottomNavigationView and navigation component?

我有以下屏幕:

Bottom Navigation stack:       [A]               [B]
Root fragments:           [HomeFragment], [SettingsFragment]
Nested fragments:                         [ProfileFragment]

我想在導航到 ProfileFragment 時實現不同的 animation:

  1. 來自 SettingsFragment
  2. 從 BottomNavigationView 從 ProfileFragment 到 [A] (HomeFragment) 然后回到 [B] (ProfileFragment)

我在支持多個后台堆棧的 bottomNavigationView 旁邊使用導航組件。 從 SettingsFragment 導航到 ProfileFragment 時,我在導航圖中使用了以下過渡動畫:

app:enterAnim="@anim/slide_right"
app:exitAnim="@anim/slide_left"

一切正常,但我不想在用戶轉到 HomeFragment 然后通過 bottomNavigationView 返回 ProfileFragment 時使用 slide_right animation。

我像這樣設置 navController:

bottomNavigationView.setupWithNavController(navController)

有什么方法可以在通過 bottomNavigationView 導航到 ProfileFragment 時使用不同的 animation(例如淡入、淡出),但在從 SettingsFragment 導航時使用我的自定義 slide_right animation?

經過大量試驗和錯誤,將導航組件版本從 2.5.3 降級到 2.5.0 對我有用。 沒有任何進一步的改變,它開始按預期工作。

暫無
暫無

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

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