android图片双指缩放,Android图片双指缩放,单指移动实现

Android 实现,图片双指缩放,单指移动。通过自定义ImageView控件实现。

ZoomDragImageView.java代码如下:

public class SwZoomDragImageView extends ImageView implements View.OnTouchListener{

private static final String TAG = SwZoomDragImageView.class.getSimpleName();

private boolean support_touch = true;//支持触摸事件

private int mode = 0;// 初始状态

private static final int MODE_DRAG = 1;//平移

private static final int MODE_ZOOM = 2;//缩放

private static final float MAX_SCALE = 4f, MIN_SCALE = 1f;//最大放大倍数,最小放大倍数

float total_scale = MIN_SCALE , current_scale;//total_scale缩放范围2-1,当小于1回弹到1;当大于2回弹到2

private Matrix matrixNow = new Matrix();

private Matrix matrixBefore = new Matrix();

private Matrix mInitializationMatrix = new Matrix();//初始缩放值

private PointF actionDownPoint = new PointF();//点击点

private PointF dragPoint = new PointF();//平移点

private PointF startPoint = new PointF();//滑动点

private PointF mInitializationScalePoint = new PointF();//初始缩放点

private PointF mCurrentScalePoint = new PointF(0, 0);//当前缩放点

private float startDis;//滑动开始距离

/** 两个手指的中间点 */

private PointF midPoint = new PointF(0,0);

public SwZoomDragImageView(Context context) {

this(context, null);

}

public SwZoomDragImageView(Context context, AttributeSet attrs) {

this(context, attrs, 0);

}

你可能感兴趣的:(android图片双指缩放)