繁体   English   中英

导航架构组件:过渡动画不适用于对话框

[英]Navigation Architecture Component: transition animations not working for dialog

我的导航图中有一个带有输入/退出动画的<dialog ,但动画不适用于该对话框。 我已经在<fragment节点上对它们进行了测试,并且工作正常。

为了澄清起见,被引用的对话框是一个 DialogFragment

这是限制还是我做错了什么?

这是我的导航图中的相关片段:

<fragment
        android:id="@+id/fragment_home"
        android:name="com.my.project.fragments.HomeFragment"
        android:label="@string/nav_home"
        tools:layout="@layout/fragment_home">
        <action
            android:id="@+id/action_fragment_home_to_fragment_dialog_new_user_welcome"
            app:destination="@id/fragment_dialog_new_user_welcome"
            app:enterAnim="@anim/nav_fade_enter_anim"
            app:exitAnim="@anim/nav_fade_exit_anim"
            app:popUpTo="@layout/fragment_home" />
    </fragment>

    <dialog
        android:id="@+id/fragment_dialog_new_user_welcome"
        android:name="com.my.project.fragments.NewUserWelcomeDialog"
        tools:layout="@layout/fragment_dialog_new_user_welcome">

        <action
            android:id="@+id/action_fragment_dialog_new_user_welcome_to_activity_discover_detail"
            app:destination="@id/fragment_discover_detail"
            app:launchSingleTop="true"
            app:popUpTo="@id/fragment_home" />
    </dialog>

这是输入动画:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
        android:duration="1000"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />
</set>

这是退出动画:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
        android:duration="500"
        android:fromAlpha="1.0"
        android:toAlpha="0.0" />
</set>

2.2.0-alpha02版本2.2.0-alpha02这是 Navigation 组件的限制。 可以查看DialogFragmentNavigator的源码

但是,您可以使用以下步骤轻松实现DialogFragment动画:

  1. anim文件夹创建一个提及进入和退出动画的样式:
    <style name="MyDialogAnimation">
        <item name="android:windowEnterAnimation">@anim/enter_anim</item>
        <item name="android:windowExitAnimation">@anim/exit_anim</item>
    </style>
  1. 在DialogFragment内部设置的样式为windowAnimations
     override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        dialog?.window?.attributes?.windowAnimations = R.style.MyDialogAnimation
    }

在此处查找更多信息

暂无
暂无

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

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