How to change fragment animation layer. I mean if first old fragment is desapearing then new fragment is comming over them.
Asked
Active
Viewed 348 times
-1
-
Possible duplicate of [Doing a push fragment animation](http://stackoverflow.com/questions/19372436/doing-a-push-fragment-animation) – Inzimam Tariq IT Jun 21 '16 at 09:28
1 Answers
1
Use Shared elements between fragments
a) Enable Window Content Transition
values/styles.xml
<style name="MaterialAnimations" parent="@style/Theme.AppCompat.Light.NoActionBar">
...
<item name="android:windowContentTransitions">true</item>
...
</style>
b) Define a common transition name
layout/fragment_a.xml
<ImageView
android:id="@+id/small_blue_icon"
style="@style/MaterialAnimations.Icon.Small"
android:src="@drawable/circle"
android:transitionName="@string/blue_name" />
layout/fragment_b.xml
<ImageView
android:id="@+id/big_blue_icon"
style="@style/MaterialAnimations.Icon.Big"
android:src="@drawable/circle"
android:transitionName="@string/blue_name" />
c) Start a fragment with a shared element
To do this you need to include shared element transition information as part of the FragmentTransaction
process.
FragmentB fragmentB = FragmentB.newInstance(sample);
// Defines enter transition for all fragment views
Slide slideTransition = new Slide(Gravity.RIGHT);
slideTransition.setDuration(1000);
sharedElementFragment2.setEnterTransition(slideTransition);
// Defines enter transition only for shared element
ChangeBounds changeBoundsTransition = TransitionInflater.from(this).inflateTransition(R.transition.change_bounds);
fragmentB.setSharedElementEnterTransition(changeBoundsTransition);
getFragmentManager().beginTransaction()
.replace(R.id.content, fragmentB)
.addSharedElement(blueView, getString(R.string.blue_name))
.commit();
Output :
for more detail visit this : https://github.com/lgvalle/Material-Animations

Harshad Pansuriya
- 20,189
- 8
- 67
- 95