I would like to add a shared elements transition using the navigation architecture components, when navigating to an other fragment. But I have no idea how. Also in the documentations there is nothing about it. Can someone help me?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
It seems it is not (yet?) supported. The transaction is actually built in
androidx.navigation.fragment.FragmentNavigator
:The animations are here (added from XML navigation), but nowhere can we change the behavior of this, and call
addSharedElement()
on the transaction.However, I believe that we may do this from activity shared element transitions.
This is not recommended as it is only between activities, and this goes against the latest Google recommendations to go with single-activity applications.
I think it's possible, as the arguments are passed before the call to
startActivity()
inandroidx.navigation.fragment.ActivityNavigator
:We would need to populate the arguments like so:
I have not tested this.
For Java
To make shared element create a method like :
At the destination class or base class you have to add below code in your onCreate().
And to make transition animation give the id and views to the sharedNavigation() like below :
With the latest library version you can just write the following:
For the transition to work you also have to specify the
sharedElementEnterTransition
and/or thesharedElementReturnTransition
in the destination Fragments onCreateView method just as Xzin explained in his answer.