Gromdroid
Gromdroid

Reputation: 493

Slide anim android

I have an homescreen with 2 buttons. When i click a button I want to slide to the next activity. I have 2 anim files:

  1. slide in:

    <set xmlns:android="schemas.android.com/apk/res/android">;
        <translate android:fromXDelta="50%p" 
            android:toXDelta="0"
            android:duration="@android:integer/config_mediumAnimTime"/> 
        <alpha
            android:fromAlpha="0.0" 
            android:toAlpha="1.0"
            android:duration="@android:integer/config_mediumAnimTime" /> 
    </set>
    
  2. fade out:

    <set xmlns:android="schemas.android.com/apk/res/android">; 
        <translate android:fromXDelta="0" android:toXDelta="-50%p"
            android:duration="@android:integer/config_mediumAnimTime"/> 
        <alpha 
            android:fromAlpha="1.0" android:toAlpha="0.0"
            android:duration="@android:integer/config_mediumAnimTime" /> 
    </set> 
    

And my java code:

 overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

But when it slide, you see the left side goes from black to the second actvitiy. Do you now how i can slide without that black side?

Upvotes: 0

Views: 1389

Answers (1)

Todd Davies
Todd Davies

Reputation: 5522

I know you have the java code right (although you are using fade_in instead of slide in mentioned in the comments).

To slide in I've used this code in the past:

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

And to slide out, it's just opposite:

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

That should work, tell me if it doesn't!

Upvotes: 2

Related Questions