I am making a simple game that displays balloons (Button
/ImageView
with background pic of a balloon). I've animated the balloons using the anim.xml
files and the balloons move pretty well around the screen.
The problem is that when you touch them, they don't do anything. The location I placed them in XML retains the power to click on them. On touching the moving pics, nothing happens.
How do I make the balloons pop on touch (i.e. change background to a broken balloon image and produce a sound)?
Don't use animation XML files for this, use ViewPropertyAnimator instead. Just call `.animate()' on your balloon view and set a direction and duration of the animation. For example this code will move your balloon by 200 pixels to the right over 1 second:
balloonView.animate().translationXBy(200).setDuration(1000);