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?
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.
The animations are basically of three types as follows: Property Animation. View Animation. Drawable Animation.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With