Android Activity Transition Animation - android

What I am trying to achieve is : start a new activity with a transition animation for the exiting activity only.
I would like to slide up the current activity, where the new activity will be behind the current one.
Here is the slide up animation : R.layout.slide_up
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="1000"
android:fromYDelta="0%"
android:toYDelta="100%" />
</set>
Here is how I am applying the activity animation transition :
overridePendingTransition ( 0 , R.anim.slide_up );
I am using 0 for the entering activity since I do not want any animation for the new activity, and it is not working (the animation is not performed). If I use an animation for entering activity too, it works (both animations are performed), like such :
overridePendingTransition ( R.anim.slide_out , R.anim.slide_up );
where R.anim.slide_out :
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="1000"
android:fromYDelta="100%"
android:toYDelta="0%" />
</set>
Any ideas ?
I am working on Android 4.1.2 and Android 4.0.4

Alter your exit animation so that it renders over top of the entering activity.
R.anim.slide_up
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:zAdjustment="top">
<translate
android:duration="1000"
android:fromYDelta="0%"
android:toYDelta="100%" />
</set>
Then you can do what you were originally doing to set the animation.
overridePendingTransition ( 0 , R.anim.slide_up );

I have exactly the same transition and such animation works for me:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromYDelta="0%" android:toYDelta="100%" android:zAdjustment="top"
android:duration="300" />

Call the below method after startActivity method.
overridePendingTransition(0,0);
This will override the default animation and do no animation. You can also give some custom animation if you like
overridePendingTransition(R.anim.animation1,R.anim.animation2);

Wherever you are calling the intent to start the Activity, you need to modify the intent.
ActivityOptions options =
ActivityOptions.makeSceneTransitionAnimation(AlbumListActivity.this);
startActivity(intent, options.toBundle());
If you have any dedicated method to setupTransitions() You can put the next two lines of code there, Else you may put them in onCreate()
getWindow().setEnterTransition(new Slide(Gravity.RIGHT).setDuration(800));
Gravity.RIGHT is what determines the direction from which you want to start your next Activity. setDuration() method is optional, for smoother Transition I used it, You don't have to.
Explore more by playing around with different Gravity and setDuration Properties.

Related

Fade slide animation when using intent for bottom navigation bar

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

How to animate activity without finishing previous activity

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>

android activity exit animation not work

I want to show exit animation when start activity exit.
this is the slide ftom left to right anim file:
<translate
android:fromXDelta="0%" android:toXDelta="-100%"
android:duration="500" />
below is where I use it to show exit animation:
Intent intent = new Intent(mContext, ActivityA.class);
startActivity(intent);
finish();
overridePendingTransition(0, R.anim.fade_out_to_left);
but exitAnim does not work, my test device is Android 4.4, KitKat.
it was like if I specify whatever enter anim resource and it works fine, but if I specify no enter anim as 0 like the example above, then the exit anim does not work either
I found solution here that works for me Android Activity Transition Animation
set android:zAdjustment="top" will renders exit animation first
Instead of passing 0 to the method use R.anim.slide_no_move:
overridePendingTransition(R.anim.slide_no_move, R.anim.fade_out_to_left);
slide no move as enter anim is not working after I tried it.
this is my slide_no_move anim file, is there anything wrong?
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="#integer/animation_long_default_duration"
android:fromXDelta="0%"
android:toXDelta="0%" />
</set>

Slide up activity

I have an activity and another activity.
I want my first activity to end when I slide up the screen. The animation should be like the activity is sliding up too. Like the notification screen.
Is that possible? I have done many Google searches before posting this question, but could not get anything.
P.S - I don't want this to be seen as a casual question since there is no code shown. I just need some point to start and I am completely baffled.
make an anim folder in res->
Make an xml file in anim folder slide_up_info.xml
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromYDelta="100%p"
android:toYDelta="0" />
</set>
slide_down_info.xml
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromYDelta="0%p"
android:interpolator="#android:anim/accelerate_interpolator"
android:toYDelta="100%p" />
</set>
no_change.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="0%p" android:toYDelta="0" android:duration="500"/>
</set>
Now when you want to activity up then write below code
Intent intent_info = new Intent(MainActivity.this,ToActivity.class);
startActivity(intent_info);
overridePendingTransition(R.anim.slide_up_info,R.anim.no_change);
For down Activity animation
Intent intent_home=new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent_home);
overridePendingTransition(R.anim.no_change,R.anim.slide_down_info);
Animations can be introduced to Activity Launch using OverridePendingTransition. Take a look at this example where they have showed a sample code. Animation between activities
To end an activity, you can call finish() on the first activity.
The know about the slideup, you can check onFling from GestureDetector or onTouch from OnTouchListener
You can also do it this way : in your animation, override the onAnimationEnd method, and use startActivity in it to launch your new activity after the end of the animation

Animation between Activity with Android

i need to understand animation on Android.
For example, my application starts with an activity with a button in the bottom, when the user click on the button i want that another activity appears with an animation from bottom to top and i want that the button becomes the "header" of this second activity.
How can i achieve this?
Thank You
Daniele
Thank you to DecodeGnome for the answer! It works!
But i have some problem with the animation when i want to close this activity, i create a anim_out.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0%p"
android:fromYDelta="0%p"
android:toXDelta="0"
android:toYDelta="100%p"
android:duration="300" />
</set>
but this doesn't work (the second parameter of overridePendingTransition what is used for?).
I try to call a new overridePendingTransition in onStop() function:
public void onStop(){
super.onStop();
overridePendingTransition(R.anim.top_to_bottom, R.anim.top_to_bottom);
}
But when i call finish to the second activity, i still see the default animation (from left to right)!
Thank you again to who'll help me.
1) Create a folder called anim in res folder
2) Add 2 new XML animations there (example, anim_in.xml & anim_out.xml)
3) put this line of code in the new activities onCreate:
overridePendingTransition(R.anim.anim_in, R.anim.anim_out);
Anim_in.xml example:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0%p"
android:fromYDelta="100%p"
android:toXDelta="0"
android:toYDelta="0%p"
android:duration="300" />
</set>
4) Place the button (header) in the top of the layout of the second activity.
Use this code:
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.top_to_bottom, R.anim.top_to_bottom);
}

Categories

Resources