Android OnImage缩放它正在超出范围
我已经完成了这个代码。当我放大母鸡时,它不应该超出边界。它工作正常,但当它接触到x=0和y=0的坐标系时,它不会最小化。我用旗子来控制它,我们可以用别的东西Android OnImage缩放它正在超出范围,android,Android,我已经完成了这个代码。当我放大母鸡时,它不应该超出边界。它工作正常,但当它接触到x=0和y=0的坐标系时,它不会最小化。我用旗子来控制它,我们可以用别的东西 int FLAG=0; else if (mode == ZOOM) { float newDistance = spacing(event); Log.i("new distance ", newDistance+"")
int FLAG=0;
else if (mode == ZOOM) {
float newDistance = spacing(event);
Log.i("new distance ", newDistance+"");
matrix.getValues(matrixValues);
matrixX = matrixValues[2];
matrixY = matrixValues[5];
width = matrixValues[0]
* (((ImageView)view).getDrawable().getIntrinsicWidth());
height = matrixValues[4]
* (((ImageView) view).getDrawable()
.getIntrinsicHeight());
dx = event.getX() - start.x;
dy = event.getY() - start.y;
// if image will go outside left bound
if (matrixX + dx < 0) {
FLAG=1;
}
if (matrixX + dx + width > view.getWidth()) {
FLAG=1;
//dx = view.getWidth() - matrixX - width;
}
// if image will go oustside top bound
if (matrixY + dy < 0) {
FLAG=1;
//dy = -matrixY;
}
// if image will go outside bottom bound
if (matrixY + dy + height > view.getHeight()) {
FLAG=1;
//dy = view.getHeight() - matrixY - height;
}
if (matrixX + dx ==0 || matrixY + dy==0){
FLAG=0;
}
if (newDistance > 10f && FLAG==0) {
matrix.set(savedMatrix);
float scale = newDistance / oldDistance;
float[] values = new float[9];
matrix.getValues(values);
float currentScale = values[Matrix.MSCALE_X];
if (scale * currentScale > MAX_ZOOM)
scale = MAX_ZOOM / currentScale;
else if (scale * currentScale < MIN_ZOOM)
scale = MIN_ZOOM / currentScale;
matrix.postScale(scale, scale, mid.x, mid.y);
}
}
break;
int标志=0;
else if(模式==缩放){
浮动新距离=间距(事件);
Log.i(“新距离”,新距离+”);
矩阵。获取值(矩阵值);
matrixX=matrixValues[2];
矩阵x=矩阵x值[5];
宽度=矩阵值[0]
*(((ImageView)视图).getDrawable().getIntrinsicWidth());
高度=矩阵值[4]
*(((ImageView)视图).getDrawable()
.getIntrinsicHeight());
dx=event.getX()-start.x;
dy=event.getY()-start.y;
//如果图像将超出左边界
if(matrixX+dx<0){
FLAG=1;
}
if(matrixX+dx+width>view.getWidth()){
FLAG=1;
//dx=view.getWidth()-matrixX-width;
}
//如果图像将超出顶部边界
if(矩阵y+dy<0){
FLAG=1;
//dy=-矩阵;
}
//如果图像将超出底部边界
if(矩阵y+dy+height>view.getHeight()){
FLAG=1;
//dy=view.getHeight()-matrixY-height;
}
如果(matrixX+dx==0 | | matrixY+dy==0){
FLAG=0;
}
如果(新距离>10f&&FLAG==0){
矩阵集(savedMatrix);
浮动比例=新距离/旧距离;
浮点[]值=新浮点[9];
矩阵。获取值(值);
float currentScale=值[Matrix.MSCALE_X];
如果(缩放*当前缩放>最大缩放)
比例=最大缩放/当前比例;
else if(缩放*当前缩放<最小缩放)
比例=最小缩放/当前比例;
矩阵。后标度(标度、标度、中x、中y);
}
}
打破
android:adjustViewBounds=“true”将此添加到您的ImageView中。我已经完成了。但图像在缩放时也会越界。