欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Android Dialog设置动画

程序员文章站 2024-03-26 08:52:29
...

创建anim文件夹,以及xml
Android Dialog设置动画

style.xml

 <style name="DialogTheme" parent="android:Theme.Dialog">
        <item name="android:windowBackground">@android:color/transparent</item><!--透明主题-->
        <item name="android:windowNoTitle">true</item>
    </style>

    <style name="MyDialogAlpha" >
        <item name="android:windowEnterAnimation">@anim/dialog_alpha_enter</item><!--进入动画-->
        <item name="android:windowExitAnimation">@anim/dialog_alpha_exit</item><!--出去动画-->
    </style>

    <style name="MyDialogScale">
        <item name="android:windowEnterAnimation">@anim/dialog_scale_enter</item>
        <item name="android:windowExitAnimation">@anim/dialog_scale_exit</item>
    </style>

    <style name="MyDialogTranslate" >
        <item name="android:windowEnterAnimation">@anim/dialog_translate_enter</item>
        <item name="android:windowExitAnimation">@anim/dialog_translate_exit</item>
    </style>

    <style name="MyDialogRotate">
        <item name="android:windowEnterAnimation">@anim/dialog_roate_enter</item>
        <item name="android:windowExitAnimation">@anim/dialog_roate_exit</item>
    </style>

MainActivity.class

  AlertDialog.Builder builder = new AlertDialog.Builder(this,R.style.DialogTheme);//R.style.DialogTheme 主题样式
                builder.setView(R.layout.dialog);
                AlertDialog dialog = builder.create();
                Window window = dialog.getWindow();
                window.setGravity(Gravity.CENTER); //Dialog在屏幕中间弹出来
                WindowManager.LayoutParams layoutParams = window.getAttributes();//获得布局属性
                layoutParams.width = 400; //设置Dialog的宽
                layoutParams.height = 200; //设置Dialog的高
                window.setWindowAnimations(R.style.MyDialogAlpha);//设置动画效果
                dialog.show();

/

相关标签: Dialog设置动画