Tuesday, February 7, 2012

Android Set animation for dialog

Android :Set animation for dialog

Problem:

*How to set animation for Dialog.

Solution:

Below i added code for how to set animation for Dialog.
it will use full for increase attractive our apps.

Dialog dlg = new Dialog(this);
dlg.getWindow().getAttributes().windowAnimations = R.style.Animations_SmileWindow;


XML style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
          <style name="Animations" />
         <style name="Animations.SmileWindow">
                <item name="@android:windowEnterAnimation">@anim/grow_from_bottom</item>
                <item name="@android:windowExitAnimation">@anim/grow_from_top</item>
        </style>
       
</resources>


Xml anim code

grow_from_bottom.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
        <scale
                android:fromXScale="0.3" android:toXScale="1.0"
                android:fromYScale="0.3" android:toYScale="1.0"
                android:pivotX="50%" android:pivotY="100%"
                android:duration="@android:integer/config_shortAnimTime"
        />
        <alpha
                android:interpolator="@android:anim/decelerate_interpolator"
                android:fromAlpha="0.0" android:toAlpha="1.0"
                android:duration="@android:integer/config_shortAnimTime"
        />
</set>

grow_from_top.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
        <scale
                android:fromXScale="0.3" android:toXScale="1.0"
                android:fromYScale="0.3" android:toYScale="1.0"
                android:pivotX="50%" android:pivotY="0%"
                android:duration="@android:integer/config_shortAnimTime"
        />
        <alpha
                android:interpolator="@android:anim/decelerate_interpolator"
                android:fromAlpha="0.0" android:toAlpha="1.0"
                android:duration="@android:integer/config_shortAnimTime"
        />
</set>


Check out this may be help you

Related Posts Plugin for WordPress, Blogger...