0

I need to translate dialog from current position to top as exit animation. In the presence of keyboard it will be available at top and should translate and exit from that position, incase if keyboard is not visible it will be in centre and should exit from there.

Tried the below snippet:

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillBefore="true"
    android:fillEnabled="true">
    <translate
        android:duration="400"
        android:toYDelta="-100%p"
     />
</set>

In this case when the dialog is not at centre (when keyboard is visible), it comes down once (to its centre position) and then translates up. This causes flickering. What am i doing wrong? How to translate smoothly

quest
  • 377
  • 2
  • 5
  • 17

2 Answers2

1

slideup.xml :

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
        android:fromAlpha="1"
        android:toAlpha="0"
        android:duration="500"/>
    <translate android:fromYDelta="0%" android:toYDelta="-100%" android:duration="500"/>
</set>

style.xml :

    <style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowAnimationStyle">@style/MyAnimation.Window</item>
    </style>
    <style name="MyAnimation.Window" parent="@android:style/Animation.Activity">
        <item name="android:windowExitAnimation">@anim/slide_up</item>
    </style>

on your code

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(STYLE_NORMAL, R.style.DialogTheme);

    }
Omar Mahmoud
  • 655
  • 5
  • 13
0

You can use the code below to show the custom dialog up and down.

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

    <translate
        android:duration="@android:integer/config_longAnimTime"
        android:fromYDelta="0%p"
        android:toYDelta="100%p" />

</set>

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

    <translate
        android:duration="@android:integer/config_longAnimTime"
        android:fromYDelta="50%p"
        android:toYDelta="0%p" />

</set>
Pang
  • 8,605
  • 144
  • 77
  • 113
shanta rao
  • 11
  • 2
  • this is similar to what i have done. It doesn't work out – quest Oct 31 '15 at 09:05
  • refer to this http://stackoverflow.com/questions/9305581/how-to-make-a-dialog-slide-from-bottom-to-middle-of-screen-in-android for more info – shanta rao Oct 31 '15 at 09:40