我将此代码与 NavigationGraph Fragment
一起使用
<fragment
android:id="@+id/editProfileFragment"
android:name="com.uvm.ui.editprofile.EditProfileFragment"
android:label="FragmentFour"
tools:layout="@layout/edit_fragment_profile" >
<action
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:enterAnim="@anim/nav_default_enter_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
android:id="@+id/action_editProfileFragment_to_profileFragment"
app:destination="@id/profileFragment" />
</fragment>
然后
navController.navigate(R.id.editProfileFragment);
用于 fragment 导航。它工作正常, fragment 替换也很好,但 enterAnim、exitAnim
等属性不起作用。没有动画的 fragment 替换。我怎么能解决这个问题?
还有一个问题是 NavigationGraph
是替换 fragment 还是添加 fragment ?我怎样才能得到堆栈的总数?
最佳答案
正如我所看到的,您正在使用 fragment 的 RID 进行导航,同时要应用事务动画,您将在操作中提供所有动画。
<action
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:enterAnim="@anim/nav_default_enter_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
android:id="@+id/action_editProfileFragment_to_profileFragment"
app:destination="@id/profileFragment" />
因此,要应用动画,请使用 Action 的 RID 进行导航。
navController.navigate(R.id.action_editProfileFragment_to_profileFragment);
默认导航组件使用 Replace Fragment Transaction。
我怎样才能得到堆栈的总数?
目前我还没有找到一种方法来获得这个计数,你的用例是什么,你能解释一下吗?
这应该有效。
关于android - 导航图动画不工作问题 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53954504/