deveLost deveLost - 3 years ago 342
Android Question

Android fragment translation right to left

i want to have a translation right to left, when a fragment disappear to show another fragment.

I have this for my translation :

ft.setCustomAnimations(R.anim.lefttoright,R.anim.righttoleft);


And my translation left & right :

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >

<translate
android:duration="700"
android:fromXDelta="-100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />

</set>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >

<translate
android:duration="700"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="100%"
android:toYDelta="0%" />

</set>


but it's not running, only translation left to right runs... why ?

Answer Source

slide1.xml

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

slide2.xml

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

Java Code

ft.setCustomAnimations(R.anim.slide1, R.anim.slide2);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download