给对话框添加动画 Dialog

先添加一个动画文件(res->anim文件夹中),文件名为a.xml

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

    <scale xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="3000"
        android:fromXScale="0.0"
        android:fromYScale="0.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1.0"
        android:toYScale="1.0">
    </scale>

</set>

接着在style.xml文件中加上:

//对话框动画
<style name="dialog_animation" parent="@android:style/Animation.Dialog">
    <item name="android:windowEnterAnimation">@anim/a</item>
    <!--<item name="android:windowExitAnimation">@anim/a</item>-->
</style>

最后在java代码中调用:

Window window = dialog.getWindow();
window.setWindowAnimations(R.style.dialog_animation);

猜你喜欢

转载自www.cnblogs.com/zhaozilongcjiajia/p/10717661.html