在我当前的项目中,我有一个包含Android Navigation Component和Firebase UI的主/详细应用程序。我试图对ImageView实现共享元素事务。在我导航到详细信息片段的情况下可以正常工作,但是用RecyclerView
弹出片段无法实现。
实际上,过渡没有应用。我认为这是时间问题。
这是保存onViewCreated
的片段的RecyclerView
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
binding.lifecycleOwner = viewLifecycleOwner
binding.viewModel = viewModel
viewModel.posts.observe(viewLifecycleOwner) { query ->
val settings = FirestoreRecyclerOptions.Builder<FeedItem>()
.setQuery(query, FeedItem::class.java)
.setLifecycleOwner(viewLifecycleOwner)
.build()
binding.recyclerView.adapter = FeedAdapter(settings, viewModel) // FirestoreRecyclerAdapter
}
viewModel.toPostEvent.observe(viewLifecycleOwner) {
it.consume()?.run { event ->
// get the image in the card
val image: ImageView = openPostEvent.view.findViewById(R.id.image);
val extras = FragmentNavigatorExtras(image to "postImage")
findNavController()
.navigate(FeedFragmentDirections.actionPost(event.postId), extras)
}
setupRecyclerView()
}
private fun setupRecyclerView() {
postponeEnterTransition()
binding.recyclerView.run {
layoutManager = LinearLayoutManager(context)
doOnPreDraw { startPostponedEnterTransition() }
}
}
如果我将Enter-Transaction延迟一秒钟,我会看到动画。但是这种延迟不是我想要的。
private fun setupRecyclerView() {
// just delay the transition for one second
postponeEnterTransition(1000, TimeUnit.MILLISECONDS)
binding.recyclerView.run {
layoutManager = LinearLayoutManager(context)
}
}
我在网上发现了一些有关RecyclerView
的问题的帖子,几乎每种解决方案都建议延迟到OnPreDraw
,所以我想我错过了有关FirestoreRecyclerAdapter
的一些特色。 / p>
非常感谢我的提示!
干杯!