首页 > 其他 > 详细

Animate a custom Dialog,自定义Dialog动画

时间:2014-10-06 00:44:39      阅读:439      评论:0      收藏:0      [点我收藏+]
Inside res/style.xml

<style name="AppTheme" parent="android:Theme.Light" />
<style name="PauseDialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowAnimationStyle">@style/PauseDialogAnimation</item>
</style>

<style name="PauseDialogAnimation">
    <item name="android:windowEnterAnimation">@anim/fadein</item>
    <item name="android:windowExitAnimation">@anim/fadeout</item>
</style>
Inside anim/fadein.xml

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="500" />

Inside anim/fadeut.xml <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/anticipate_interpolator" android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="500" /> MainActivity Dialog imageDiaglog= new Dialog(MainActivity.this,R.style.PauseDialog);

 

http://stackoverflow.com/questions/4817014/animate-a-custom-dialog


<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="PauseDialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowAnimationStyle">@style/PauseDialogAnimation</item>
    </style>

    <style name="PauseDialogAnimation">
        <item name="android:windowEnterAnimation">@anim/spin_in</item>
        <item name="android:windowExitAnimation">@android:anim/slide_out_right</item>
    </style>
</resources>

 


The windowEnterAnimation is one of my animations and is located in res\anim. The windowExitAnimation is one of the animations that is part of the Android SDK.

Then when I create the Dialog in my activities onCreateDialog(int id) method I do the following.

Dialog dialog = new Dialog(this, R.style.PauseDialog);

// Setting the title and layout for the dialog
dialog.setTitle(R.string.pause_menu_label);
dialog.setContentView(R.layout.pause_menu);
Alternatively you could set the animations the following way instead of using the Dialog constructor that takes a theme.

Dialog dialog = new Dialog(this);
dialog.getWindow().getAttributes().windowAnimations = R.style.PauseDialogAnimation;

 

Animate a custom Dialog,自定义Dialog动画

原文:http://www.cnblogs.com/niray/p/4007846.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!