Android Animation - Button stays clickable

余生颓废 提交于 2019-11-27 08:22:02

问题


I am making a game in which I have 5 buttons, looking like clouds, falling from the "sky". That means that when my activity starts, 'clouds' cannot be seen, since the marginTop is set to -100dp. From that position they start falling down untill they get lost on the bottom side of the screen.

The thing is, I need those buttons to be clickable, during the process of animation.

So far, I found some documentation about how I can make the buttons clickable AFTER the animation ends. But I don't need that. I need to be able to click on the buttons through the animation time itself.

NOTE: I need something that works with versions before 3.0.

Anybody has any link to documentation or some example or anything ?


回答1:


After doing some research, I found out that there are two types of animations:

View Animation and Proprety Animation.

The view animation can only animate View objects. It also lack a variety of animations, since it can do only stuff as scale, rotate, move... It cannot change background color, for example. Also, the dissadvantage of the View Animation is that it only change the position of where the View object is DRAWN. Phisically, it still stays in the same position. That's why the button is unclickable, after the View Animation is finished upon it.

Property Animation, in the other hand, can animate both View and non-View objects and it doesn't have constraints as the View Animation. When objects are moved, for example, with the property animation, they are not just drawn on some other position on the screen, but they are actually MOVED there.

Now, Property Animation is a lot more complex to write than the View Animation, so if you don't really need all the advantages of the Property Animation, it is suggested to use View Animation.

Source: Property vs View Animation

Tutorial and SupportLybrary up to API 1: nineoldandroids




回答2:


You can change the buttons to imageViews and then do

 imageView.setOnClickListener(myListener)

then set myListener to do whatever you previously wanted to happen on the buttons onClick. Your activity will have to implement OnClickListener

Added bonus: you can make the images look like clouds :)



来源:https://stackoverflow.com/questions/18333269/android-animation-button-stays-clickable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!