在我的Android應用程序中,我使用了ZoomImageView Class。其中所有的作品完美,除了我的ImageView.it停止縮放,拖動和旋轉達到後MAX縮放級別。我的圖像停止在最大程度縮放後移動
下面是我的的onTouchEvent()
@Override
public boolean onTouch(View v, MotionEvent event) {
mScaleDetector.onTouchEvent(event);
ImageView view = (ImageView) v;
float scale;
dumpEvent(event);
// Handle touch events here...
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_CANCEL:
touch = false;
invalidate();
break;
case MotionEvent.ACTION_DOWN:
if (isInBitmap(event)) {
touch = true;
savedMatrix.set(matrix);
if (MainActivity.mCurrentView != null) {
MainActivity.mCurrentView.setInEdit(false);
MainActivity.mCurrentView.setInEdit(false);
}
if (bottom.getVisibility() == INVISIBLE) {
rel.bringToFront();
setAlpha(0.6f);
}
bottom.setVisibility(INVISIBLE);
start.set(event.getX(), event.getY());
mode = DRAG;
left.setVisibility(VISIBLE);
right.setVisibility(VISIBLE);
bottom.setVisibility(INVISIBLE);
invalidate();
postInvalidate();
requestLayout();
}
break;
case MotionEvent.ACTION_UP:
touch = false;
rel_frame.bringToFront();
left.bringToFront();
right.bringToFront();
bottom.bringToFront();
// MainActivity.drawabletext.bringToFront();
setAlpha(1.0f);// first finger lifted
invalidate();
break;
case MotionEvent.ACTION_POINTER_UP: // second finger lifted
mode = NONE;
//lastEvent=null;
invalidate();
break;
case MotionEvent.ACTION_POINTER_DOWN: // first and second finger down
if (isInBitmap(event)) {
touch = true;
if (bottom.getVisibility() == INVISIBLE) {
rel.bringToFront();
setAlpha(0.6f);
}
oldDist = spacing(event);
if (oldDist > 5f) {
savedMatrix.set(matrix);
midPoint(mid, event);
mode = ZOOM;
}
if (oldDist > 10f) {
savedMatrix.set(matrix);
midPoint(mid, event);
}
lastEvent = new float[4];
lastEvent[0] = event.getX(0);
lastEvent[1] = event.getX(1);
lastEvent[2] = event.getY(0);
lastEvent[3] = event.getY(1);
d = rotation(event);
invalidate();
postInvalidate();
requestLayout();
}
break;
case MotionEvent.ACTION_MOVE:
if (isInBitmap(event)) {
if (mode == DRAG) {
matrix.set(savedMatrix);
matrix.postTranslate(event.getX() - start.x, event.getY() - start.y); // create the transformation in the matrix of points
} else if (mode == ZOOM) {
// pinch zooming
float newDist = spacing(event);
Log.d(TAG, "newDist=" + newDist);
if (newDist > 5f) {
matrix.set(savedMatrix);
scale = newDist/oldDist;
matrix.postScale(scale, scale, mid.x, mid.y);
}
if (lastEvent != null) {
newRot = rotation(event);
float r = newRot - d;
matrix.postRotate(r, getMeasuredWidth()/2,
getMeasuredHeight()/2);
}
}
invalidate();
postInvalidate();
}
break;
}
invalidate();
postInvalidate();
requestLayout();
view.setImageMatrix(matrix);
invalidate();
postInvalidate();
requestLayout();// display the transformation on screen
return true;
}
請人幫我出從這個Problem.Thanks提前
'invalidate(); postInvalidate(); requestLayout();'重複兩次?你爲什麼這樣做? – pskink
嘿@Alis試試我的代碼,讓我知道...希望這會幫助你。 –
@pskink刷新的ImageView以防萬一它停止堅持並開始工作,因爲我想要的。 – Alis