How to Provide Animation When Calling Another Activity in Android

How to provide animation when calling another activity in Android?

Since API 16 you can supply an activity options bundle when calling Context.startActivity(Intent, Bundle) or related methods. It is created via the ActivityOptions builder:

Intent myIntent = new Intent(context, MyActivity.class);
ActivityOptions options =
ActivityOptions.makeCustomAnimation(context, R.anim.fade_in, R.anim.fade_out);
context.startActivity(myIntent, options.toBundle());

Don't forget to check out the other methods of the ActivityOptions builder and the ActivityOptionsCompat if you are using the Support Library.



API 5+:

For apps targeting API level 5+ there is the Activities overridePendingTransition method. It takes two resource IDs for the incoming and outgoing animations. An id of 0 will disable the animations. Call this immediately after the startActivity call.

i.e.:

startActivity(new Intent(this, MyActivity.class));
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

API 3+:

You can prevent the default animation (Slide in from the right) with the Intent.FLAG_ACTIVITY_NO_ANIMATION flag in your intent.

i.e.:

Intent myIntent = new Intent(context, MyActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
context.startActivity(myIntent);

then in your Activity you simply have to specify your own animation.

This also works for the 1.5 API (Level 3).

How to apply slide animation between two activities in Android?

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);

new Handler().postDelayed(new Runnable() {
public void run() {

/* Create an intent that will start the main activity. */
Intent mainIntent = new Intent(SplashScreen.this,
ConnectedActivity.class);
mainIntent.putExtra("id", "1");

//SplashScreen.this.startActivity(mainIntent);
startActivity(mainIntent);
/* Finish splash activity so user cant go back to it. */
SplashScreen.this.finish();

/* Apply our splash exit (fade out) and main
entry (fade in) animation transitions. */
overridePendingTransition(R.anim.mainfadein,R.anim.splashfadeout);
}
}, SPLASH_DISPLAY_TIME);
}

How to provide flip animation when calling another activity in android

For adding the flip animation When loading an activity.First you should add animation to the resource "anim" folder.the animation should be of flipping in and out.the in your java file after calling an intent you should add this piece of code.

(this).overridePendingTransition(R.anim.incoming, R.anim.outgoing); 

This will help you to Solve your problem.

Android: how to make a vertical Activity transition with another Activity

Use overridePendingTransition to change the Activity animation.

For the 1st case you can use:

Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_top);

For the 2nd case choose other animations and call overridePendingTransition
in onBackPressed or after finish. overridePendingTransition should be called right after your activity finishes.

If you are looking for animations, take a look at the google API samples.
https://android.googlesource.com/platform/development/+/master/samples/ApiDemos/res/anim/
There a lot of simple and useful animation xml's.

But abc_slide_in_bottom and abc_slide_in_bottom are in the google appcompat lib since some years. abc_slide_out_bottom and abc_slide_in_top also.

Start animation from another class

Instead of passing a Activity object, try just passing a Context. And in your activity, use Megegy me = new Megegy(txt, this);

Also,

public class Megegy {
TextView txt;
Activity activity;
Fadede fa;

public Megegy(TextView txt, Context context){
this.activity = activity;
this.txt = txt;
this.fa = new Fadede(context, txt);
}
}

Right now the Fadede object is being constructed while activity and txt are still null, so instead you should create the object from within Megegy's constructor.

How to go to an activity with the back key press animation using an intent?

I ended up trying to find out the duration by trial and error (bisectional search). I followed this tutorial (which I linked to in the question). I arrived at a value of 233 for the duration.

Step-by-step:

Make an anim folder in the res directory. In that folder make two files:

slide_from_left.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="-100%p"
android:toXDelta="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:duration="233" />
</set>

slide_to_right.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="100%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:duration="233" />
</set>

After the call to start the activity, call overridePendingTransition(), like this:

startActivity(backIntent);
overridePendingTransition(R.anim.slide_from_left, R.anim.slide_to_right);

Animation between Activity with Android

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.



Related Topics



Leave a reply



Submit