Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 889
Yi Son Avatar asked Sep 18 '13 20:09

Yi Son


People also ask

Is animation possible on Android?

On Android 4.4 (API level 19) and higher, you can use the transition framework to create animations when you swap the layout within the current activity or fragment. All you need to do is specify the starting and ending layout, and what type of animation you want to use.

Which animation system is used in Android application?

The animations are basically of three types as follows: Property Animation. View Animation. Drawable Animation.

How do you show and hide a view with a slide up down animation Android?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken button to show /hide linear layout with animation.


1 Answers

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);
like image 92
Rishabh Srivastava Avatar answered Sep 21 '22 13:09

Rishabh Srivastava