setup Resize Touch Listener - Android android.view

Android examples for android.view:MotionEvent

Description

setup Resize Touch Listener

Demo Code

import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Interpolator;
import android.view.animation.OvershootInterpolator;

public class Main {

  public static Interpolator OVERSHOOT = new OvershootInterpolator(2.8f);
  public static final int ANIM_DURATION = 300 ;

  public static View.OnTouchListener setupResizeTouchListener(View v) {
    View.OnTouchListener touchListener = new View.OnTouchListener() {
      @Override//  w w w . j  a  v a  2s  . c  o  m
      public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
          v.animate().setInterpolator(OVERSHOOT).scaleX(.85f).scaleY(.85f).setStartDelay(0).setDuration(ANIM_DURATION)
              .setListener(null);
        } else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL
            || event.getAction() == MotionEvent.ACTION_OUTSIDE) {
          v.animate().setInterpolator(OVERSHOOT).scaleX(1f).scaleY(1f).setStartDelay(0).setDuration(ANIM_DURATION)
              .setListener(null);
        }
        return false;
      }
    };
    v.setOnTouchListener(touchListener);
    return touchListener;
  }

}

Related Tutorials