开发者

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 fla开发者_如何学JAVAsh 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);

            }
        });
    }


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


I had the same problem (on a samsung galaxy s). I found my answer at Activity animation not working in Galaxy Tab Turns out animations are turned off by default on samsung devices. (It's a setting: Go to Settings -> display -> animations and then turn on the All animations and you will be able to see the animations)


Try this,

 button.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent myIntent = new Intent(v.getContext(),
                ActivityTwo.class);
        startActivityForResult(myIntent, 0);
        overridePendingTransition(R.anim.zoomextra, 0);
         finish();


    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜