noob noob - 1 year ago 70
Android Question

How to build Animator slide up/down in XML for android?

I've been trying to find out how to build an animator (xml) that will cause a slide up and slide down effect. How would that work? Thanks

Answer Source

Make a folder anim in the res folder of the project. Now add slide_up.xml for slide_up animation. Then add slide_down.xml for slide down animation.

Code for slide_down.xml:

<set xmlns:android="">  
    <translate android:fromXDelta="0" android:toYDelta="-1000" android:duration="1500"/>

Code for slide_up.xml:

<set xmlns:android="">  
    <translate android:fromXDelta="0" android:toYDelta="1000" android:duration="1500"/>

Then load the animation in onCreate method consequently:

Animation slideUp = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up);

To start it attach it to object you want to be animated:

ImageView img = (ImageView) findViewById(;

Hope I've helped you. :-)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download