public classDoubleScaleImageViewextendsAppCompatImageViewimplementsView.OnTouchListener,ViewTreeObserver.OnGlobalLayoutListener{
private boolean isFirst = false;
private float doubleScale;// 双击放大的值 private Matrix mScaleMatrix;
private float defaultScale;// 默认的缩放值 private int mLastPinterCount;// 记录上一次多点触控的数量 private float mLastX;
private float mLastY;
private int mTouchSlop;
private boolean isCanDrag;
private boolean isCheckLeft;
private boolean isCheckTop;
private GestureDetector mGestureDetector;
publicDoubleScaleImageView(Context context){
this(context, null);
}
publicDoubleScaleImageView(Context context, AttributeSet attrs){
this(context, attrs, 0);
}
publicDoubleScaleImageView(Context context, AttributeSet attrs,intdefStyleAttr){
super(context, attrs, defStyleAttr);
mScaleMatrix = new Matrix();
setScaleType(ScaleType.MATRIX);
setOnTouchListener(this);
// getScaledTouchSlop是一个距离,表示滑动的时候,手的移动要大于这个距离才开始移动控件。如果小于这个距离就不触发移动控件 mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override publicbooleanonDoubleTap(MotionEvent