简体   繁体   中英

Button translate animation not working as expected

I wanted to add animation to my activity with 5 buttons. When I click on any button, it disappears going down. However, when I click on another button, it goes down as well but the first button I clicked also reappears and goes down. I want the buttons clicked to not be visible when I click on another button. Here is the code snippet:

 animation = new TranslateAnimation(0,0,0,1000);
 animation.setDuration(1000);
 animation.setFillAfter(true);

Then on my Onclick:

 button1.startAnimation(animation);
 option1.setVisibility(0);

When I use VIEW.Gone. The layout becomes messed up..

Try to use Invisible instead of gone. View.GONE will release occupied space by this view causing your layout issues. Invisible will hide your view but won't change the position of any other views.

Not sure if I understand you right yet it looks you always start the animation from 0,0. You should instead start the animation from where the button is at the moment. So if the button is already down it is just animated to go form being down to being down. If you want to make the efforts you can of course already check where the button is and animate only if the button is not already where it should move to.

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