Skip to content

Instantly share code, notes, and snippets.

@orhanobut
Created January 28, 2014 10:34
Show Gist options
  • Star 41 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save orhanobut/8665372 to your computer and use it in GitHub Desktop.
Save orhanobut/8665372 to your computer and use it in GitHub Desktop.
Up down animation for dialog fragment
// Slide up animation
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="@android:integer/config_mediumAnimTime"
android:fromYDelta="100%"
android:interpolator="@android:anim/accelerate_interpolator"
android:toXDelta="0" />
</set>
// Slide dowm animation
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="@android:integer/config_mediumAnimTime"
android:fromYDelta="0%p"
android:interpolator="@android:anim/accelerate_interpolator"
android:toYDelta="100%p" />
</set>
// Style
<style name="DialogAnimation">
<item name="android:windowEnterAnimation">@anim/slide_up</item>
<item name="android:windowExitAnimation">@anim/slide_down</item>
</style>
// Inside Dialog Fragment
@Override
public void onActivityCreated(Bundle arg0) {
super.onActivityCreated(arg0);
getDialog().getWindow()
.getAttributes().windowAnimations = R.style.DialogAnimation;
}
@Vovaxo
Copy link

Vovaxo commented Apr 11, 2016

Can we use @animator(objectAnimator) animation instead of @anim

@ponnex
Copy link

ponnex commented May 1, 2016

it should be android:toYDelta="0%p" instead of android:toXDelta="0" in slide_up.xml

@meisamphp
Copy link

Thank you , This is very GOOD

@Nishanthbabu
Copy link

thank u

@shahabsaalami
Copy link

tnx

@gejiaheng
Copy link

gejiaheng commented Sep 28, 2016

Thank you!

I think we don't need to put <translate> in <set> element. According to View Animation:

The file must have a single root element: either an <alpha>, <scale>, <translate>, <rotate>, or <set> element that holds a group (or groups) of other animation elements (even nested <set> elements).

And also, if you set the y translation to 100%, the dialog will disappear when it's bottom edge gets to the bottom of window. Thus we will see a flash. It's not smooth. So I add y translation to 150%, and the dialog will slide in and out completely across the bottom of window.

@amintabar
Copy link

Thank you!
I used 'slide_in_up.xml' and 'slide_out_down.xml' file from android resources. You can find out it in android SDK folder.

@CapnSpellcheck
Copy link

I wonder why those resource files 'slide_in_up.xml' exist? They are not exposed, and don't seem to be used.

@Davids89
Copy link

Thank you, very usefull

@vvbhandare
Copy link

Thank you. Very much useful

@TusharKhandekar1
Copy link

Thank You

@manishpatelgt
Copy link

Thank you. Really helpful

Copy link

ghost commented Aug 13, 2019

Thank you! really helpful

@sureshmaidaragi1919
Copy link

helpful

@dinabandhuM
Copy link

Helpful

@MarcosPoloLinux
Copy link

Thank you very very much! simple and efectivity i love u

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment