简体   繁体   English

如何在使用导航组件和 safeArgs 从回收器视图导航到片段时添加共享元素转换?

[英]How to add shared element transition when navigating from recycler view to a fragment while using navigation components and safeArgs?

I want to show shared element transition from my recycler view to a fragment class, I've wriiten the following code:我想显示从我的回收器视图到片段 class 的共享元素转换,我编写了以下代码:

holder.view.setOnClickListener {
            val extras = FragmentNavigatorExtras(
                holder.view.ivPersonImage to "imageView"
            )
            it.findNavController().navigate(
                HomeFragmentDirections.actionNavHomeToTransactionFragment(
                    customerId,
                    customerName,
                    customerPhoneNumber,
                    imageString
                ), null, null, extras
            )
        }

it's showing error at.navigate as:它显示错误 at.navigate 为:

 None of the following functions can be called with the arguments supplied: 
private open fun navigate(@NonNull p0: NavDestination, @Nullable p1: Bundle?, @Nullable p2: NavOptions?, @Nullable p3: Navigator.Extras?): Unit defined in androidx.navigation.NavController
public open fun navigate(@IdRes p0: Int, @Nullable p1: Bundle?, @Nullable p2: NavOptions?, @Nullable p3: Navigator.Extras?): Unit defined in androidx.navigation.NavController

in Fragment class, I'm using:在片段 class 中,我正在使用:

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        sharedElementEnterTransition = TransitionInflater.from(context).inflateTransition(android.R.transition.move)
    }

seems like safeArgs are not allowing to show transition.似乎 safeArgs 不允许显示转换。 I'm new to Android and finding it very difficult to understand transitions and animations.我是 Android 的新手,发现很难理解过渡和动画。 Please help me, I'm stuck here for so many days now请帮帮我,我在这里卡了这么多天了

SafeArgs allows you to set shared transition. SafeArgs允许您设置共享过渡。 Just check navigate() documentation , there is overload with two parameters: NavDirections and Navigator.Extras .只需检查navigate() 文档,有两个参数重载: NavDirectionsNavigator.Extras So your code should look like this:所以你的代码应该是这样的:

holder.view.setOnClickListener {
    val extras = FragmentNavigatorExtras(holder.view.ivPersonImage to "imageView")
    it.findNavController().navigate(
        HomeFragmentDirections.actionNavHomeToTransactionFragment(
            customerId,
            customerName,
            customerPhoneNumber,
            imageString
        ), 
        extras
    )
}

暂无
暂无

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

相关问题 使用导航组件单击 RecyclerView 项目时如何从 RecyclerView OnClick 侦听器更改片段 - How to change fragment from the Recycler View OnClick Listener when RecyclerView item is clicked using Navigation Components 导航回片段时恢复回收器视图状态 - 使用 jetpacks 导航架构 - Restore recycler view state when navigating back to the fragment - using the jetpacks navigation architecture 使用 SafeArgs 导航到 Fragment 时检查参数是否存在 - Check if arguments exists when navigating to Fragment using SafeArgs 如何共享元素从片段到活动的转换 - how to Shared element transition from a fragment to an activity Jetpack Navigation 中从 RecyclerView 到 Detail Fragment 的共享元素转换 - Shared element transition in Jetpack Navigation from RecyclerView to Detail Fragment 如何使用导航组件安全参数将列表作为参数传递给片段 - How to pass a List as an argument to a Fragment using Navigation Component safeargs 如何使用 Android 导航组件实现从 RecyclerView 项目到 Fragment 的共享过渡元素? - How to implement shared transition element from RecyclerView item to Fragment with Android Navigation Component? 如何将不参与从片段 A 的共享元素转换的视图添加到片段 B? - How to add views to Fragment B that are not involved in a shared element transition from Fragment A? 如何将回收器视图添加到片段 - How to add a recycler view to fragment 导航组件:将安全参数从活动传递到片段 - Navigation Component: pass safeArgs from activity to a fragment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM