问题
I am currently doing an animation from the material spec design, now I want to enable to do a point of origin animation which is showed here:
Sample Animation Link
How can I do that animation of pre lollipop? Is there a way doing it in pre-lollipop devices?
回答1:
I've achieved this point of Origin creating a XML based approach and applying it to your custom Theme.
Create anim/anim_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="0.0"
android:toXScale="1.0"
android:fromYScale="0.0"
android:toYScale="1.0"
android:fillAfter="false"
android:startOffset="200"
android:duration="200"
android:pivotX = "100%"
android:pivotY = "100%"
/>
<translate
android:fromYDelta="50%"
android:toYDelta="0"
android:startOffset="200"
android:duration="200"
/>
</set>
Then Create anim/anim_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1.0"
android:toXScale="0.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:fillAfter="false"
android:duration="200"
android:pivotX = "100%"
android:pivotY = "100%"
/>
<translate
android:fromYDelta="0"
android:toYDelta="50%"
android:duration="200"
/>
</set>
This animation origin pops a window or dialog fragment from right bottom corner of the screen. Modify pivotX and pivotY to change the location of the origin
Define this windows animation in your style.xml
<style name="InOut.Window" parent="@android:style/Animation.Activity">
<item name="android:windowEnterAnimation">@anim/anim_in</item>
<item name="android:windowExitAnimation">@anim/anim_out</item>
</style>
Lastly apply this animation to all the window for your custom Theme that you would have created.
<style ....>
...
<item name="android:windowAnimationStyle">@style/InOut.Window</item>
</style>
来源:https://stackoverflow.com/questions/29452501/point-of-origin-animation-android