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
FirstFragment
first_fragment.xml
SecondFragment
second_fragment.xml
I tested it. It is worked.
Since 1.0.0-alpha06 the navigation component supports adding shared element transitions between destinations. Just add FragmentNavigatorExtras to navigate() call. More details: https://developer.android.com/guide/navigation/navigation-animate-transitions#shared-element
So let's say that you have two Fragments, FragmentSecond and FragmentThird. Both have ImageView with the same transitionName, let's say : "imageView"
Just define a normal action between these fragments.
In FragmentSecond, let's add our extras
So we're saying that we want to share that ImageView, with that transitionName, with ThirdFragment
And then in ThirdFragment :
The only thing that we have to do is load the image in the two fragments from the same URL. The URL can be passed between fragments using a Bundle Object and pass it in the navigate call or as a destination argument in the navigation graph.
If you need it, i am preparing a sample about Navigation and there's SharedElementTransition too :
https://github.com/matteopasotti/navigation-sample
I took reference from this github sample https://github.com/serbelga/android_navigation_shared_elements
It is working properly.
To make this work from a recyclerView's ImageView the setup everything like the following:
within the adapter this does the trick:
You don't have to specify the transition name within the adapter's item's xml but simply set it from code as soon as the item gets clicked.
The onClickedAction looks like:
and you pass it to your ViewHolder.
In the second Fragment you set the transition name to the ImageView in xml:
and assign the transition like
I was finally able to get this to work: On Fragment B:
Just make sure you have your transition names right in your views and you have NO entertTransition on Fragment B