I have a navigation bar at the bottom with icons. When I click on an icon a new activity starts with intent.
context.startActivity(intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP));
Like this.
If I test it on my Android Pixel emulator the animation is always from bottom to top when a new activity starts.
If I test it on my physical android device (Android 7.1) the animation is always from right to left when a new activity starts. When I close an activity the animation goes from left to right away.
I want always this slide animation (like on my physical device). What do I have to do?
I added
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
In the onCreate() of the activites, so I have the slide when the activity starts, but no slide animation when the activity close.
Thanks for your help
you'll need 2 new animation files in your anim folder and some code in the Activity which you want to close with the animation, add changes to onBackPressed method
First the animation files: left_to_right.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="500"
android:fromXDelta="-100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
right_to_left.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="500"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="100%"
android:toYDelta="0%" />
</set>
And in Activity do the following:
#Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left);
}
PS Also be aware that even if your code is okay, your phone might have animation turned off
I am using ViewFlipper with Left and Right buttons to switch back and forth between images. After implementing the code below and clicking right button the image will:
It changes instantly to next image > Slide in what was the current image > change back to next image again. I am trying to simply slide current image out left > next image to slide in from the right.
res\anim\in_from_right.xml and res\anim\out_to_left.xml respectively:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="1400"
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="1400"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="-100%"
android:toYDelta="0%" />
</set>
and java:
buttonRight.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
flippy.setOutAnimation(ChestBurner.this, R.anim.in_from_right);
flippy.setInAnimation(ChestBurner.this, R.anim.out_to_left);
flippy.showNext();
}
});
Turns out in all matters of android studio that are complete mysteries either a restart or update will do the trick.
The above error was rectified after updating all API's in the SDK.
In my application I want to animate my activity from right to left. Till now I am try this :
startActivity(intent);
finish();
overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left);
and this working fine but my previous activity got finished. What I want to do the same animation without finishing previous activity.
while trying like this :
startActivity(intent);
overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left);
only newly started activity go into animation and previous activity does get any effect. How can I animate both activity without finishing the previous one?
You should use Handler in this case!
Put time on Handler on First Activity. During this time animate your first activity. After this step handler give the control to your second activity and then you start animation on second activity
I think that your animations might be the problem. I have the same effect using the following animation files:
slide_in_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="#android:integer/config_mediumAnimTime"
android:fromXDelta="100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
slide_out_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="#android:integer/config_mediumAnimTime"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="-100%"
android:toYDelta="0%" />
</set>
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".
Then, onBackPressed() Acyivity B should "come back", entering from the left side of the screen and overlapping the ActivityB that stay unmoved.
Not sure if you tried this combination, but should work.-
startActivityForResult(intent, 500);
overridePendingTransition(R.anim.enter_from_left, R.anim.stay_still);
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.
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>
Try this
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);
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
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.
I am trying to start an animation AFTER 1 second. I have used the attribute "android:startOffset" in my XML file, but it does not work completely the way I expected. I was expecting the view to NOT EVEN BE DRAW in its initial position (that is, the position set in the attributes "fromXDelta" and "fromYDelta") before the offset I set has passed. Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="sequentially"
android:shareInterpolator="false" >
<translate
android:duration="2000"
android:startOffset="1000"
android:fromXDelta="-70%p"
android:fromYDelta="0%p"
android:interpolator="#android:anim/linear_interpolator"
android:toXDelta="+0%p"
android:toYDelta="0%p" />
</set>
If I try to move my view using the above animation, the view is drawn IMMEDIATELY at the position -70% of the screen. Then the one second passes and then, as expected, the animation kicks in and starts to move the view. However, I DO NOT want the view to be drawn at all before that 1 second!. How can I achieve this?
Thank you in advance.
UPDATE
I am calling the above XML just after a startActivity call (the *R.anim.animation_coming_in* below), like this:
startActivity(new Intent(this, ThankYouActivity.class));
overridePendingTransition(R.anim.animation_coming_in, R.anim.animation_coming_out);
You could try using a pair of alpha animations with very short duration so that the view is hidden until it's needed. Something like this:
<set ...>
<alpha
android:fromAlpha="0.0"
android:toAlpha="0.0"
android:duration="1"
android:startOffset="0" />
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="1"
android:startOffset="1000" />
<translate
...
/>
</set>
Alternatively, you could implement this set of animations in code. Doing so would enable you to use a Handler to start the animation after a delay so that the view is hidden until the animation starts.