Saturday, 27 December 2014

Creating Dialog WindowAnimation Programmatically?



I want to set animation to my Dialog. The challenge here is that I want to do this programatically.


The reason for that is I have too many different size of dialogs and I don't want to create a new animation file for each type of dialog.


As of now, this if what I am doing:


res/anim/anim_myDialog_SlideUp.xml file:



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

<translate android:fromXDelta="0%"
android:toXDelta="0%"
android:fromYDelta="200%"
android:toYDelta="0%"
android:duration="400"/>
</set>


res/anim/anim_myDialog_SlideDown.xml file:



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

<translate android:fromXDelta="0%"
android:toXDelta="0%"
android:fromYDelta="0"
android:toYDelta="200%"
android:duration="400"/>
</set>


In my res/values/styles.xml file:



<style name="slideUpAndDown">
<item name="android:windowEnterAnimation">@anim/anim_myDialog_SlideUp</item>
<item name="android:windowExitAnimation">@anim/anim_myDialog_SlideDown</item>
</style>

<style name="myDialogSlideUpAndDown" parent="@android:style/Theme.Dialog">
<item name="android:windowAnimationStyle">@style/slideUpAndDown</item>
</style>


In my MainActivity.cs file:



Dialog myDialog = new Dialog(this, Resource.Style.myDialogSlideUpAndDown);


I can create the animations programmatically with no problem. The problem is how can I set those animations to my Dialog?


If I create a Dialog and not set it's style in the constructor:



Dialog myDialog = new Dialog(this);


Then I have the option to do this to set it's animation:



myDialog.Window.SetWindowAnimations(int);


SetWindowAnimations requires an int. Can I create this animation int manually?


Sorry for the long explanation and thank you for your time.


No comments:

Post a Comment