android - 弹出输入动画不适用于 Jetpack 导航组件
问题描述
我一直在使用 Jetpack Navigation 组件(2.3.5,虽然我也测试过旧版本)并尝试在两个简单目的地之间添加转换。但是,使用该popEnterAnim
属性指定的转换根本不会运行。相反,重新进入的片段会立即出现。
我设法用一个非常简单的例子重新创建了它。片段布局只是一个TextView
.
主要活动
<androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph" />
class ActivityMain : AppCompatActivity(R.layout.main)
片段 1
class Fragment1 : Fragment(R.layout.fragment_1) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
view.setOnClickListener {
findNavController().navigate(R.id.action_fragment1_to_fragment2)
}
}
}
片段 2
class Fragment2: Fragment(R.layout.fragment_2)
导航图
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/nav_graph.xml"
app:startDestination="@id/fragment1">
<fragment
android:id="@+id/fragment1"
android:name="uk.henrytwist.projectsource.Fragment1"
android:label="MainFragment" >
<action
android:id="@+id/action_fragment1_to_fragment2"
app:destination="@id/fragment2"
app:enterAnim="@anim/transition_rise_up_enter"
app:exitAnim="@anim/transition_fade_exit"
app:popEnterAnim="@anim/transition_fade_pop_enter"
app:popExitAnim="@anim/transition_rise_up_pop_exit" />
</fragment>
<fragment
android:id="@+id/fragment2"
android:name="uk.henrytwist.projectsource.Fragment2"
android:label="Fragment2" />
</navigation>
解决方案
事实证明,这实际上是由于 AndroidX 片段库 ( androidx.fragment:fragment:1.3.2
) 中的一个错误,该错误现已在版本中得到纠正1.3.3
。更改日志确认修复:
修复了 Fragment 1.3.2 中引入的回归,该回归会导致 popEnter 动画在弹出包含 setPrimaryNavFragment 操作的 FragmentTransaction 时无法运行,例如 NavHostFragment 使用的那些。(I38c87, b/183877426)
推荐阅读
- stack - 为什么“已检测到任务iot_thread中的堆栈溢出”不断出现?
- python - 警告:tensorflow:已编译加载的模型,但尚未构建编译的指标
- javascript - 使用 NGiNX 的 ShareX NodeJS 应用程序 - 返回 Localhost 而不是域
- r - 使用markdown转PDF时ggplot的问题
- flutter - Json Response 获取单个字段(Appwrite)
- python - 如何按时间索引从向量中访问数组
- cmd - 如何将字符串/查询写入 cmd 中的配置单元查询文件?
- c++ - 如何处理在 C++ 中定义的 C char*
- android-studio - 权限异常
- javascript - 商品数量决定销售价格 简单JS计算器