我的问题是我有一个ImageView,我将一个图像设置为Imageview的setBackgroundResource,然后在图像的触摸事件中不执行旋转,放大,缩小。
以下是我的触摸事件代码: -
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (v == mImageViewMask) {
System.out.println("Vande Mataram");
mImageViewMask = (ImageView) v;
r = Math.atan2(event.getX() - mImageViewMask.getWidth() / 2,
mImageViewMask.getHeight() / 2 - event.getY());
rotation = (int) Math.toDegrees(r);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
savedMatrix.set(matrix);
start.set(event.getX(), event.getY());
Log.d(TAG, "mode=DRAG");
mode = DRAG;
break;
case MotionEvent.ACTION_POINTER_DOWN:
oldDist = spacing(event);
Log.d(TAG, "oldDist=" + oldDist);
if (oldDist > 10f) {
savedMatrix.set(matrix);
midPoint(mid, event);
mode = ZOOM;
Log.d(TAG, "mode=ZOOM");
}
break;
case MotionEvent.ACTION_MOVE:
if (mode == DRAG) {
matrix.set(savedMatrix);
matrix.postTranslate(event.getX() - start.x, event.getY()
- start.y);
} else if (mode == ZOOM) {
updateRotation(rotation);
newDist = spacing(event);
Log.d(TAG, "newDist=" + newDist);
if (newDist > 10f) {
matrix.set(savedMatrix);
scale = newDist / oldDist;
matrix.postScale(scale, scale, mid.x, mid.y);
}
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
mode = NONE;
Log.d(TAG, "mode=NONE");
break;
}
// Perform the transformation
mImageViewMask.setImageMatrix(matrix);
}
return true;
}
对不良英语交流表示抱歉。
先谢谢。
答案 0 :(得分:0)
请将图像设置为源。
,而不是setBackgroundImage