One button animation (Imagebutton) android

Asked

Viewed 52 times

0

I would like to know how to do when the user clicks on the button it gets bigger and smaller when releasing, simulating a zoom effect on the component.

1 answer

0


Use the onTouchListener event, and by taking Motionevents inside that event you increase/decrease the size.

@Override
public boolean onTouch(View v, MotionEvent motionEvent) {
    int action = motionEvent.getAction();
    if (action == MotionEvent.ACTION_DOWN) {
        v.animate().scaleXBy(100f).setDuration(5000).start();
        v.animate().scaleYBy(100f).setDuration(5000).start();
        return true;
    } else if (action == MotionEvent.ACTION_UP) {
        v.animate().cancel();
        v.animate().scaleX(1f).setDuration(1000).start();
        v.animate().scaleY(1f).setDuration(1000).start();
        return true;
    }

    return false;
}
  • Dude.. Can you give me an example with some little snippet of code ?

  • I edited the answer with the code ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.