3

I'm a rookie and noob but is it possible to add another image when an image button with animation is pressed?

mmBs
  • 8,421
  • 6
  • 38
  • 46

1 Answers1

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