Animation of a button (ImageButton) android [closed]

0

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

    
asked by anonymous 21.06.2017 / 19:23

1 answer

0

Use the onTouchListener event, and getting MotionEvents within that event increases / decreases 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;
}
    
21.06.2017 / 20:10