Android rotate animation between two activity?

前端 未结 1 2123
甜味超标
甜味超标 2020-12-08 09:23

How to put rotate animation between two activities.when is startactivity and next activity is start with rotate animation

相关标签:
1条回答
  • 2020-12-08 09:39

    Here's a tutorial on how to add an animation when transistioning between two activities. However, instead of using a translate animation like in the article, you'll want to use a rotate animation. For more information on animations, checkout this documentation.

    Putting those two things together, here's what you need to do. First, where you make the call to start the new activity do this:

    //Calls a new Activity  
    startActivity(new Intent(this, NewActivity.class));  
    
    //Set the transition -> method available from Android 2.0 and beyond  
    overridePendingTransition(R.anim.rotate_out,R.anim.rotate_in);
    

    Then create the following two animations in your xml:

    rotate_out.xml

    <?xml version="1.0" encoding="utf-8"?>   
    <set xmlns:android="http://schemas.android.com/apk/res/android">  
       <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />  
       <rotate android:fromDegrees="0" android:toDegrees="90" android:pivotX="25%" />
    </set>
    

    rotate_in.xml

    <?xml version="1.0" encoding="utf-8"?>   
    <set xmlns:android="http://schemas.android.com/apk/res/android">  
       <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />  
       <rotate android:fromDegrees="90" android:toDegrees="0" android:pivotX="-25%" />
    </set>
    

    You can play with the fromDegrees, toDegrees, and pivotX values to get exactly what you'd like.

    0 讨论(0)
提交回复
热议问题