问题:我限制了最大和最小缩放,一切正常,但是:
- 如果我尝试缩放小于最小值,那么要缩放+,则需要在相反方向上进行相同数量的运动。缩放+也是如此。在技术方面,它看起来像这样:
values[Matrix.MSCALE_X]发生变化,尽管在此之前是:
m.reset();
m.setScale(sx1, sx1);
其中sx1是一个固定值。这是我的代码:
public boolean onScale(ScaleGestureDetector detector) {
try{
saved_gest_scale = newScale;
newScale *= detector.getScaleFactor();
scaleFactor = newScale / oldScale;
target_img_width *= 1/scaleFactor;
if (target_img_width > width)//limit max zoom
{
//fit on screen:
m = new Matrix();
m.reset();
float w_coef = img_width / width;
float sx1 = 1/w_coef;
m.setScale(sx1, sx1);
///========
//apply new size
float sx2 = target_img_width/width;
sx2 = 1/sx2;
m.setScale(sx2, sx2);
float[] values = new float[9];
m.getValues(values);
//center image:
float globalX = values[Matrix.MTRANS_X];
float globalY = values[Matrix.MTRANS_Y];
float wid = values[Matrix.MSCALE_X]*img_width;
float heig = values[Matrix.MSCALE_Y]*img_height;
m.postTranslate(width/2 - wid/2, height/2-heig/2);
if (wid <= width)//limit min-zoom
{
newScale = sx1;
m = new Matrix();
m.reset();
m.setScale(sx1, sx1);
wid = sx1*img_width;
heig = sx1*img_height;
debug.setText(wid + "<width" + "mx=" + values[Matrix.MSCALE_X] );
m.postTranslate(width/2 - wid/2, height/2-heig/2);
}
iw.setImageMatrix(m);
}
oldScale = newScale;
}catch (Exception xx)
{
debug.setText("detector "+ xx.toString());
}
return true;
}
请帮忙。