I'm trying to recreate the same motion as exemplified here: https://material.io/develop/android/theming/motion
Specifically the example 2 under MaterialContainerTransform
The detailed explanation suggests an example that transitions from RecyclerView
to ViewPager
, but this does not apply to my case which is to a Fragment
.
As it stands I am unable to make this work properly and since this is such a generic search term any possible examples I hope to find are in a sea of generic results that contain RecyclerView
and Fragment
.
This is as far as I got, but only the Hold
animation on exit is working.
For this project I am using the Navigation Architecture Component in Java
Fragment A
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setExitTransition(new Hold());
}
// this is the recycler view item click listener
private ItemClickCallback getClickCallback() {
return (view) -> {
FragmentNavigator.Extras extras = new FragmentNavigator.Extras
.Builder()
.addSharedElement(view, view.getTransitionName())
.build();
NavHostFragment
.findNavController(this)
.navigate(R.id.action_navigation, null, null, extras);
};
}
Fragment B
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setSharedElementEnterTransition(new MaterialContainerTransform());
}
That is it. There is no difference when clicking an item with that implemented or without, except for the delay as a result of the Hold
animation.
Is this a bug in the animation library or is this not being done right? The documentation does not show clearly how to implement this for this case specifically and I assume this is not being done right as a result of the lack of documentation.