工程結(jié)構(gòu)
這里是做記錄的脓钾,廢話不多說先上項(xiàng)目圖大體上分為四個部分
- gestures包 與手勢相關(guān)的操作
- log包 日志相關(guān)
- scrollerproxy包 與滾動相關(guān)
-
剩下的就是核心代碼 (圖片的縮放)
工程結(jié)構(gòu)
gestures包
-
UML類圖
類圖 - 接口
- GestureDetector
public interface GestureDetector {
//處理Imageview的OnTouchListener,詳情見PhotoViewAttacher 類
boolean onTouchEvent(MotionEvent ev);
//是否真正縮放
boolean isScaling();
//是否正在拖拽舟陆,也就是手指沒有離開Imagview
boolean isDragging();
//將一些手指狀態(tài)返回,外部做處理
void setOnGestureListener(OnGestureListener listener);
}
public interface OnGestureListener {
//拖拽時(shí)調(diào)用 dx 水平方向發(fā)生的位置 dy 豎直方向發(fā)生的位移
void onDrag(float dx, float dy);
//快速滑動離開ImageView時(shí)調(diào)用担扑,startX startY手指離開時(shí)的X,Y 坐標(biāo)
//velocityX 水平方向的速度,velocityY 豎直方向的速度
void onFling(float startX, float startY, float velocityX,float velocityY);
//縮放時(shí)調(diào)用 縮放比例 手指點(diǎn)擊的地方的X Y 坐標(biāo)
void onScale(float scaleFactor, float focusX, float focusY);
}
- 工具類 VersionedGestureDetector
public final class VersionedGestureDetector {
//根據(jù)版本生成一個 GestureDetector 對象
public static GestureDetector newInstance(Context context,
OnGestureListener listener) {
final int sdkVersion = Build.VERSION.SDK_INT;
GestureDetector detector;
if (sdkVersion < Build.VERSION_CODES.ECLAIR) {
detector = new CupcakeGestureDetector(context);
} else if (sdkVersion < Build.VERSION_CODES.FROYO) {
detector = new EclairGestureDetector(context);
} else {
detector = new FroyoGestureDetector(context);
}
detector.setOnGestureListener(listener);
return detector;
}
}