Issue
I want to make an app which contains list of items. When the user clicks an item, I want to animate it with material motion effect described in here
Is android libraries contains it as natively? If not, is there a 3. party library for this animation?
You can see the animation in this video: video link
Solution
You can use shared element Transition
https://github.com/codepath/android_guides/wiki/Shared-Element-Activity-Transition
https://github.com/googlesamples/android-ActivitySceneTransitionBasic
https://github.com/toddway/MaterialTransitions
https://github.com/afollestad/shared-element-transition-samples
FirstFragment fragmentOne = ...;
SecondFragment fragmentTwo = ...;
// Check that the device is running lollipop
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Inflate transitions to apply
Transition changeTransform = TransitionInflater.from(this).
inflateTransition(R.transition.change_image_transform);
Transition explodeTransform = TransitionInflater.from(this).
inflateTransition(android.R.transition.explode);
// Setup exit transition on first fragment
fragmentOne.setSharedElementReturnTransition(changeTransform);
fragmentOne.setExitTransition(explodeTransform);
// Setup enter transition on second fragment
fragmentTwo.setSharedElementEnterTransition(changeTransform);
fragmentTwo.setEnterTransition(explodeTransform);
// Find the shared element (in Fragment A)
ImageView ivProfile = (ImageView) findViewById(R.id.ivProfile);
// Add second fragment by replacing first
FragmentTransaction ft = getFragmentManager().beginTransaction()
.replace(R.id.container, fragmentTwo)
.addToBackStack("transaction")
.addSharedElement(ivProfile, "profile");
// Apply the transaction
ft.commit();
}
else {
// Code to run on older devices
}
OUTPUT
Answered By - Aditya Vyas-Lakhan
Answer Checked By - Timothy Miller (JavaFixing Admin)