下载地址:代码下载
该效果就是仿win8磁铁效果
效果图如下:
package com.ljp.ani;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Camera;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ImageView;
@SuppressLint("HandlerLeak")
public class MyImageView extends ImageView {
public static final int Rotate_Handler_Message_Start = 1;
public static final int Rotate_Handler_Message_Turning = 2;
public static final int Rotate_Handler_Message_Turned = 3;
public static final int Rotate_Handler_Message_Reverse = 6;
public static final int Scale_Handler_Message_Start = 1;
public static final int Scale_Handler_Message_Turning = 2;
public static final int Scale_Handler_Message_Turned = 3;
public static final int Scale_Handler_Message_Reverse = 6;
private boolean isAntiAlias = true;
private boolean scaleOnly = false;
private boolean isSizeChanged = false;
private boolean isShowAnimation = true;
private int rotateDegree = 10;
private boolean isFirst = true;
private float minScale = 0.95f;
private int vWidth;
private int vHeight;
private boolean isAnimationFinish = true, isActionMove = false,
isScale = false;
private Camera camera;
boolean XbigY = false;
float RolateX = 0;
float RolateY = 0;
OnViewClick onclick = null;
public MyImageView(Context context) {
super(context);
camera = new Camera();
}
public MyImageView(Context context, AttributeSet attrs) {
super(context, attrs);
camera = new Camera();
}
public void SetAnimationOnOff(boolean oo) {
isShowAnimation = oo;
}
public void setOnClickIntent(OnViewClick onclick) {
this.onclick = onclick;
}
@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isFirst) {
isFirst = false;
init();
}
canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG
| Paint.FILTER_BITMA