简体   繁体   中英

Best way to create slide down animation on Android app?

I'm just getting into Android development and basically I have 5 rectangular buttons stacked on each other.

When I click one (let's say the top one), I want the other 4 to slide down, and another set of buttons or whatever to show between them.

And I want the transitions to be sliding rather than just appearing.

Any suggestions on how to implement that or what functions to use?

First you need to define the Animation in XML like this:

Slide down from the top:

<set xmlns:android="http://schemas.android.com/apk/res/android">  
    <translate android:fromYDelta="-100%" android:toYDelta="0%" android:duration="1000"/>
</set>

Slide up out of the screen:

<set xmlns:android="http://schemas.android.com/apk/res/android">  
    <translate android:fromYDelta="0%" android:toYDelta="-100%" android:duration="1000"/>
</set>

You can load the Animation like this:

Animation slide = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_down);

And then you can apply the Animation to your View like this:

view.startAnimation(slide);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM