Hopeless
Hopeless

Reputation: 4773

OverridePendingTransition is not working strangely

I'm a beginnner in Xamarin Android programming as well as in Android programming in general. I successfully run the following code with expected effect:

//in the context of the main Activity
StartActivity(someIntent);
OverridePendingTransition(Android.Resource.Animation.SlideInLeft, 
                          Android.Resource.Animation.SlideOutRight);

Now I would like to create my own animations for sliding from left and sliding out from right using XML declaration. I put my XML files under the anim folder with names slideInLeft.xml and slideOutRight.xml respectively. Here are the files' content:

slideInLeft.xml:

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

slideOutRight.xml:

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

Now the code is just simply changed to this:

//in the context of the main Activity
StartActivity(someIntent);
OverridePendingTransition(Resource.Animation.SlideInLeft, 
                          Resource.Animation.SlideOutRight);

But the animation is not working, the new Activity is just shown after a short of delay (looks like being equal the duration of sliding in which is 300ms).

This is confusing me. I don't know why and how to make this work.

Upvotes: 1

Views: 311

Answers (2)

Huy
Huy

Reputation: 3363

You try to set duration more longer to see the transition :)

slideInLeft.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >
    <translate android:duration="5000" 
    android:fromXDelta="-100%" 
    android:toXDelta="0%"/>
    <alpha android:duration="5000" 
    android:fromAlpha="0.0" 
    android:toAlpha="1.0" />
</set>

slideOutRight.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >
    <translate android:duration="5000" 
    android:fromXDelta="0%" 
    android:toXDelta="100%"/>
    <alpha android:duration="5000" 
    android:fromAlpha="1.0" 
    android:toAlpha="0.0" />
</set>

Upvotes: 0

himanshu1496
himanshu1496

Reputation: 1921

Try changing your xml files to:

slideInLeft

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="-100%p" android:toXDelta="0"
        android:duration="350"/>
</set>

AND

slideOutRight

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="100%p"
        android:duration="350"/>
</set>

This should work.

Upvotes: 1

Related Questions