Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a custom animation between Android Activities

So I know you can use your own animation between activities using the overidePendingTransition method. I set up a transition between two activites and it works perfect on my emulator but I see no transition when I flash the app on to my phone. How can this be?

My emulator is running 2.2 as is my phone

Here is my onCreate method

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final Button button = (Button) findViewById(R.id.close);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent myIntent = new Intent(ActivityTransitionActivity.this, ActivityTwo.class);
                ActivityTransitionActivity.this.startActivity(myIntent);
                overridePendingTransition(R.anim.fadein, R.anim.fadeout);

            }
        });
    }
like image 273
Bobby Strickland Avatar asked Aug 26 '11 05:08

Bobby Strickland


People also ask

What is translate animation in Android?

Translate Animation can change the visual appearance of an object, but they cannot change the objects themselves. That is, if you apply a translate animation to a view, it would move to a new position, but its click events would not get fired; the click events would still get fired at its previous position.


1 Answers

In your style.xml define your animation

    <style  name="Animation.CustomAnimation">
        <item name="android:activityOpenEnterAnimation">@anim/slide_in_left</item> When opening a new activity, this is the animation that is run on the next activity
        <item name="android:activityOpenExitAnimation">@anim/slide_out_right</item>When opening a new activity, this is the animation that is run on the previous activity (which is exiting the screen)
        <item name="android:activityCloseEnterAnimation">@anim/slide_in_right</item>When closing the current activity, this is the animation that is run on the next activity (which is entering the screen). 
        <item name="android:activityCloseExitAnimation">@anim/slide_out_left</item>When closing the current activity, this is the animation that is run on the current activity (which is exiting the screen). 
        </style>

<style parent="android:style/Theme.Light.NoTitleBar.Fullscreen" name="app_theme">
     <item name="android:windowBackground">@drawable/splash</item>
     <item name="android:windowAnimationStyle">@style/Animation.CustomAnimation</item>

    </style>

<application android:icon="@drawable/icon" android:label="@string/app_name"
     android:theme="@style/app_theme">

apply app_theme to your application in android manifest

like image 161
Mohit Avatar answered Nov 15 '22 07:11

Mohit