Best way to create slide down animation on Android app?
Asked Answered
S

1

13

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?

Soutache answered 18/9, 2013 at 20:35 Comment(1)
Did it worked for u?Tannenwald
T
34

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);
Tannenwald answered 4/7, 2014 at 12:0 Comment(6)
How do you set the 'hidden' view that will slide down initially? Do you set the height to 0, or the visibility to 'GONE'?Othaothe
Visibility will be "GONE".Tannenwald
this one slides the view from top of the screen. What to do if I the starting point should be bottom of action bar?Futch
This only translates view from the bottom to top, and the blank placeholder which all views inside animation view take place after animation is first seen then animation view translates. This is not slidedown animation.It is translating view. For real slidedown I believe more work should have be done.Quarrelsome
excuse me, but should I create another XML ? if so under what folder ??Wise
@SígvardrÓlavrsson anim folder.Tannenwald

© 2022 - 2024 — McMap. All rights reserved.