OnImage Zoom它越界了

时间:2013-10-25 10:18:26

标签: android

我已经完成了这段代码。当我放大母鸡它不应该超出界限。它的工作正常。但是当它接触x = 0和y = 0的坐标时,它不会最小化。我在这里使用FLAG来控制它,我们可以使用其他东西。

 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;

0 个答案:

没有答案