本示例实现Android通过手势可以实现图像的拖拽功能。运行效果如下:
开发之通过手势实现图像拖拽功能-jquery实现拖拽功能">
代码如下 | 复制代码 |
package com.android.drag;import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.MotionEvent; import android.view.View; /** class ImageDragView extends View { private float x1; public ImageDragView(Context context) { @Override float size = event.getSize(); int szi = (int) size; DisplayMetrics metrics = getResources().getDisplayMetrics(); x1 = event.getX(); x2 = x1 + dx; invalidate(); return true; @Override float r = (float) Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) Paint paint = new Paint(); |