Thursday, 11 December 2014

How to NOT center android dialog?



I want to use a dialog but I don't want it to be centered vertically on the screen.


I created a Dialog and used SetContentView() to apply the layout.

I also applied style and no title option. Here is what I did.



mydialog = new Dialog (context, Resource.Style.myDialogAnim);
mydialog.RequestWindowFeature ((int)WindowFeatures.NoTitle);
mydialog.SetContentView (myDialogView);
mydialog.SetCanceledOnTouchOutside (false);


The style I applied to this dialog is here:



<style name="myDialogAnim" parent="@android:style/Theme.Dialog">
<item name="android:windowAnimationStyle">@style/slideInAndOut</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
<style name="slideInAndOut">
<item name="android:windowEnterAnimation">@anim/anim_animatein</item>
<item name="android:windowExitAnimation">@anim/anim_animateaway</item>
</style>


When I use this dialog, the dialog animates in from the fromYDelta location to the toYDelta location in anim_animatein but as soon as the animation is done, it centers itself vertically.


I need it to be centered horizontally on the screen but NOT vertically.


How can I do this?


Thank you for your time.


No comments:

Post a Comment