0

I am very weak with animations in Android. I need to make my Fragments "flip" just 100% equal to the ViewPager animation.

Here is my slide_in_left.xml code

<?xml version="1.0" encoding="utf-8"?>
<set>
  <translate xmlns:android="http://schemas.android.com/apk/res/android"
   android:fromXDelta="-100%"
   android:toXDelta="0"
   android:interpolator="@android:anim/decelerate_interpolator"
   android:duration="5000"/>
</set> 

Here is my **slide_out_right.xml** code

<?xml version="1.0" encoding="utf-8"?>
<set>
  <translate xmlns:android="http://schemas.android.com/apk/res/android"
   android:fromXDelta="0"
   android:toXDelta="-100%"
   android:interpolator="@android:anim/decelerate_interpolator"
   android:duration="5000"/>
</set>

But this is not equal to ViewPager sliding animation. Instead, the existing Fragment exists from left and the new Fragment enters from left.

Apart from that, I need this animation to exit the existing fragment from left and new one to enter from right. How can I fix this issue?

halfer
  • 19,824
  • 17
  • 99
  • 186
PeakGen
  • 21,894
  • 86
  • 261
  • 463
  • Refer this link.Hope it will help you.http://stackoverflow.com/questions/20802369/slide-left-right-animation-between-fragments – AndiM Jan 15 '14 at 05:43

2 Answers2

1

Don't do any changes in slide_out_right.xml. But in slide_in_left.xml, just replace

android:fromXDelta="-100%"

with

android:fromXDelta="100%"
user543
  • 3,623
  • 2
  • 16
  • 14
  • Thanks for the reply. But there is a small difference. ViewPager existing Fragment exists from left, new one enter from right. Here it is other way around – PeakGen Jan 15 '14 at 05:54
0

First, in your slide_out_right.xml, change

android:toXDelta="-100%p"

to

android:toXDelta="100%p"

And I think you should as well set animation for slide to right, a slide_in_right.xml and slide_out_left.xml

see FragmentTransaction#setCurrentAnimations

bladefury
  • 825
  • 6
  • 16