Android - Animation, hiding and displaying a menu

Asked

Viewed 176 times

1

I’m having a problem creating an animation. I have a button in the action bar that when clicking on it, either displays or hides a menu bar. So far it is displaying or hiding using GONE and VISIBLE. I would like to add an animation, this menu is just below the action bar, so by clicking to hide the menu, I would like it to move up, hiding it. By clicking to show the menu, I would like it to move down, showing you. Another problem is that the rest of the layout should follow the movement that is chosen. Does anyone know an example for this problem? Thank you!

  • Douglas, could you use the ViewPropertyAnimator, which is quite simple, but requires your minimum API to be 12. You could follow this tutorial own Android Developers blog.

  • I tried, I couldn’t get the animation done right...

  • It could include the code you’ve done so far?

1 answer

1

To make an animation of a component is very simple. See the example below:

EditText cadastroEdtNome
cadastroEdtNome.startAnimation(AnimationUtils.loadAnimation(CadastroCliente.this, R.anim.slide_up));

Ready! Now you just need the XML code for the animations. What I sent you is this one:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >

    <scale
        android:duration="250"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:interpolator="@android:anim/linear_interpolator"
        android:toXScale="1.0"
        android:toYScale="0.0" />

</set>

But there are many others on the internet, and you can even create yours if you want!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.