5

I know that are some example over the internet and also here on Stackoverflow I found many examples but belive it or not, none of them supply me needs. Even I have asked a similar question few time ago and I have stuck again into this problem. Basically is the same question but in the opposite direction. I can do whatever animation I want with Activity B but the problem here is Activity A which I could animate just in few scenarios. Basically ActivityA play enter_left only in this combination:

overridePendingTransition(R.anim.enter_from_right, R.anim.exit_on_left);

What I want to do is to animate(move) just the Activity A either on startActivity() and onBackPressed() while Activity B stay unmoved on the screen. Activity A swould allways be drawn on top(as a sliding menu, I could do this with Activity B). I really thought that the above snippet will do the work:

Intent intent = new Intent(ActivityA.this, ActivityB.class);
                startActivityForResult(intent, 500);
                overridePendingTransition(R.anim.stay_still, R.anim.exit_on_left);

but this does not even play any animation, while

//this is the animation for onBackPressed()
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        overridePendingTransition(R.anim.enter_from_left, 0);
    }

animates Activity A as I want but Activity B suddenly disappears from screen and I want to stay (setting (R.anim.enter_from_left, R.anim.stay_still) does nothing).

I have prepared all 5 necessary animations:

enter_from_left

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

<translate
    android:duration="500"
    android:fromXDelta="-100%"
    android:toXDelta="0%" />
</set>

exit_on_left

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

<translate
    android:duration="500"
    android:fromXDelta="0%"
    android:toXDelta="-100%" />
</set>

enter_from_right

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

    <translate
        android:duration="500"
        android:fromXDelta="100%"
        android:toXDelta="0%" />
   </set>

exit_on_right

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

    <translate
        android:duration="500"
        android:fromXDelta="0%"
        android:toXDelta="100%" />
   </set>

stay_still

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

    <translate
        android:duration="500"
        android:fromXDelta="0%"
        android:toXDelta="0%" />
</set>

I have tried a lot of combinations but non of them worked. Could you please tell me if is this animation possible and if can it be done in this way? I will post an image, to be more clear what I want to do:

So, first step: on startActivity(), ActivityA should leave the screen from the left side and while moving, the Activity B shoull allready "be there", "below it".

enter image description here

Then, onBackPressed() Acyivity B should "come back", entering from the left side of the screen and overlapping the ActivityB that stay unmoved.

enter image description here

Community
  • 1
  • 1
AlexAndro
  • 1,918
  • 2
  • 27
  • 53

5 Answers5

0

Not sure if you tried this combination, but should work.-

startActivityForResult(intent, 500);
overridePendingTransition(R.anim.enter_from_left, R.anim.stay_still);
ssantos
  • 16,001
  • 7
  • 50
  • 70
  • This makes `Activity B` enter from left while `Activity A` stays. The first argument is the animation for entering(new created) activity. – AlexAndro Nov 05 '13 at 00:03
0

I could find that the next one works very nice with fragments fragmentTransaction.setCustomAnimations(R.anim.stay_still,R.anim.exit_on_left);
while overridePendingTransition(R.anim.stay_still, R.anim.exit_on_left); does not work with activity.

On the other hand the reverse,

overridePendingTransition(R.anim.enter_from_left, 0); or fragmentTransaction.setCustomAnimations(R.anim.enter_from_left, 0);

does not work with activity neither with fragments. The most close approach that works was transaction.setCustomAnimations(R.anim.stay_still,R.anim.exit_on_left, R.anim.enter_from_left,R.anim.exit_on_right);

If anyone has any other solution, I'm still waiting to hear it and it will be appreciated.

AlexAndro
  • 1,918
  • 2
  • 27
  • 53
0

5 years later but there exists a solution for this. These two functions needs be implemented in the activity which will override the default transition.

@Override
public void startActivity(Intent intent) {
    super.startActivity(intent);
    overridePendingTransition(R.anim.from_right_in, R.anim.from_left_out);
}

@Override
public void startActivityForResult(Intent intent, int requestCode) {
    super.startActivityForResult(intent, requestCode);
    overridePendingTransition(R.anim.from_right_in, R.anim.from_left_out);
}

from_right_in.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="100%p" android:toXDelta="0" android:interpolator="@android:interpolator/accelerate_decelerate" android:duration="300"/>
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />
</set>

from_left_out.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="0" android:toXDelta="-100%p" android:duration="300"/>
    <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="300" />
</set>
Sascha Heim
  • 301
  • 1
  • 4
  • 15
0

Try this

  1. Add animations for activity transition in/out, in intent call like

    startActivity(new Intent(this,toActivity));
    overridePendingTransition( R.anim.slide_in, R.anim.slide_out);
    
  2. Here is animations file, add this in anim folder

    slide_in.xml

    <?xml version="1.0" encoding="utf-8"?>
    <translate xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromYDelta="100%p" android:toYDelta="0%p"
        android:duration="300"/>
    

    slide_out.xml

    <?xml version="1.0" encoding="utf-8"?>
    <translate xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="@android:integer/config_longAnimTime"
        android:fromYDelta="0%p"
        android:toYDelta="100%p" />
    

Thanks

Android Geek
  • 8,956
  • 2
  • 21
  • 35
-1

I don't know if i really understand what you want, but if you want to create a sliding Menu, you could use this tutorial to implement it, it works just fine - It's an alternative to resolve your problem -:

http://developer.android.com/training/implementing-navigation/nav-drawer.html

But your have to use FragmentActivity instead of Activity. If you want an example, just ask for it and i will post it. Good luck.

R00t
  • 186
  • 1
  • 2
  • 14
  • No, I don't want this because a I have a flux of some activities that has to share this animation. This does not suppose to be a sliding menu. – AlexAndro Nov 05 '13 at 06:34