dialog、activity等进入、退出动画实现

无论是dialog还是activity,都是附着在window上的,因此,可以借用window的相关属性实现进入退出动画。
以dialog为例:

dialog.getWindow().getAttributes().windowAnimations = R.style.edit_dialog_style;

R.style.edit_dialog_style

<style name="edit_dialog_style" parent="android:Animation">
        <item name="android:windowEnterAnimation">@anim/edit_label_enter_anim</item>
        <item name="android:windowExitAnimation">@anim/edit_label_exit_anim</item>
    </style>

animation

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:duration="500">

    <translate
        android:fromYDelta="100%"
        android:toYDelta="0%"/>
</set>

版权声明:本文为A199581原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。