Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace android Launcher activity animations

I'm creating my own Android Launcher.

The problem is:

  • When I launch an activity, it slides left...
  • When I close it, it slides right...
  • This is annoying and ugly!

I've alread been able to remove the launch animation with:

Intent launch_intent = new Intent("android.intent.action.MAIN");
launch_intent.addCategory("android.intent.category.LAUNCHER");
launch_intent.setComponent(new ComponentName(packageName, name));
launch_intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);

activity.startActivity(launch_intent);

My objective is to:

  • Also remove the close application animation.
  • Or change the launch/close default animations.

Thanks in advance!

like image 814
inversus Avatar asked Oct 25 '11 17:10

inversus


People also ask

What is Launcher activity Android?

Launcher Activities are the activities that can be launched for a given intent. For example, when you press an app icon on the home screen, the StartActivity intent starts the activity you have specified as the launcher activity.

What is transition animation in Android?

Android's transition framework allows you to animate all kinds of motion in your UI by simply providing the starting layout and the ending layout.


2 Answers

I had a look at the Android API demos, As was suggested you should use the "overridePendingTransition()" method, it sets the animation of the incoming activity and the animation of the outgoing activity.
The method shoud be added afer startActivity() or after finish():

    Intent launch_intent = new Intent("android.intent.action.MAIN");
    launch_intent.addCategory("android.intent.category.LAUNCHER");
    launch_intent.setComponent(new ComponentName(packageName, name));  
    activity.startActivity(launch_intent);
    overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);

The transitions are standard android animations, for example the zoom_enter will be something like that:

<set xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/decelerate_interpolator">
    <scale android:fromXScale="2.0" android:toXScale="1.0"
           android:fromYScale="2.0" android:toYScale="1.0"
           android:pivotX="50%p" android:pivotY="50%p"
           android:duration="@android:integer/config_mediumAnimTime" />
</set>

If you also want to set an animation when your activity is being closed, for example when user presses the back or home button, you should add the overridePendingTransition() to the onPause() method.
If you want to set an animation when your activity is being launched by some other application, add the overridePendingTransition() before the super.onCreate().

like image 121
eladrich Avatar answered Sep 21 '22 03:09

eladrich


For displaying standard launcher animation you have to apply a specific theme for your main launcher activity. This theme should be (or should be inherited from) android:Theme.Wallpaper. android:theme="@android:style/Theme.Wallpaper"

For such theme Android Framework provides specific animations that you may see for standard Launcher.

like image 25
max Avatar answered Sep 21 '22 03:09

max