I'm a rookie and noob but is it possible to add another image when an image button with animation is pressed?
Asked
Active
Viewed 900 times
3
-
you could change the image on the imagebutton by setting the onTouchListener, returning false in it, and then may be perform the action in the onclick listener – Rat-a-tat-a-tat Ratatouille May 09 '14 at 13:03
1 Answers
2
Yes, it is possible. Use the TransitionDrawable
, Luke!
mYourImageButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Drawable[] layers = new Drawable[2];
layers[0] = getResources().getDrawable(R.drawable.image1);
layers[1] = getResources().getDrawable(R.drawable.image2);
TransitionDrawable transition = new TransitionDrawable(layers);
transition.setCrossFadeEnabled(true);
mYourImageButton.setImageDrawable(transition);
transition.startTransition(500 /*animation duration*/);
}
});

erakitin
- 11,437
- 5
- 44
- 49