Reputation: 457
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
Upvotes: 0
Views: 1662
Reputation: 3067
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);
}
Upvotes: 1
Reputation: 11
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>
Upvotes: 0