Point of origin animation android

て烟熏妆下的殇ゞ 提交于 2019-12-22 11:36:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!