Flip card transition between two activities Android

前端 未结 2 1384
一整个雨季
一整个雨季 2020-12-25 08:55

I am trying to implement the Flip card transition effect between two activities in my app by taking help from : http://blog.robert-heim.de/karriere/android-st

相关标签:
2条回答
  • 2020-12-25 09:10

    Based on user1672053's answer, you need to add a start offset to the from_middle.xml resource which is equal to the duration of the to_middle.xml animation resource.

    0 讨论(0)
  • 2020-12-25 09:11

    Disclaimer: This is not a an actual 3D Animation Flip. This merely imitates it, though some don't agree. Give it a try and if you like it, great! If you don't, my apologies.

    In my early days of learning to code, I was having issues implementing a proper 3D Animation flip, so I went with this, it simulated it enough to satisfy my needs, but to each her/his own. To do what I did, first make sure that you have a folder called anim under your res folder for your project. Then you will need to create two xml files (I have mine called from_middle and to_middle). Below is the code for each of those:

    from_middle.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <scale
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromXScale="0.0" android:toXScale="1.0"
        android:pivotX="50%" 
        android:fromYScale="1.0" android:toYScale="1.0"
        android:pivotY="50%"         
        android:duration="500" />
    

    to_middle.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <scale
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromXScale="1.0" android:toXScale="0.0"
        android:pivotX="50%" 
        android:fromYScale="1.0" android:toYScale="1.0"
        android:pivotY="50%"        
        android:duration="500" />
    

    After those are created, all you need is one line of code to run this animation, which you should be placed after you start your next activity:

    overridePendingTransition(R.anim.from_middle, R.anim.to_middle);
    

    Done! Now run it!

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