java.lang.IllegalArgumentException异常解决

自定义随手势缩放图片控件的时,图片方法再滑动会出现java.lang.IllegalArgumentException异常,
解决方法就是在onTouch方法里面try,catch此异常:

case MotionEvent.ACTION_MOVE: {
            **try{**
                float fFirstX = event.getX();
                float fFirstY = event.getY();

                int nCounts = event.getPointerCount();

                if (1 == nCounts) {
                    mOldCounts = 1;
                    float dx = (fFirstX - mFirstX) / v.getWidth();
                    float dy = (fFirstY - mFirstY) / v.getHeight();
                    mZoomControl.pan(-dx, -dy);
                } else if (1 == mOldCounts) {
                    mSecondX = event.getX(event.getPointerId(nCounts - 1));
                    mSecondY = event.getY(event.getPointerId(nCounts - 1));
                    mOldCounts = nCounts;
                } else {
                    float fSecondX = event
                            .getX(event.getPointerId(nCounts - 1));
                    float fSecondY = event
                            .getY(event.getPointerId(nCounts - 1));

                    double nLengthOld = getLength(mFirstX, mFirstY, mSecondX,
                            mSecondY);
                    double nLengthNow = getLength(fFirstX, fFirstY, fSecondX,
                            fSecondY);

                    float d = (float) ((nLengthNow - nLengthOld) / v.getWidth());

                    mZoomControl.zoom((float) Math.pow(20, d),
                            ((fFirstX + fSecondX) / 2 / v.getWidth()),
                            ((fFirstY + fSecondY) / 2 / v.getHeight()));

                    mSecondX = fSecondX;
                    mSecondY = fSecondY;
                }
                mFirstX = fFirstX;
                mFirstY = fFirstY;
            **}catch(IllegalArgumentException ex){
                ex.printStackTrace();
            }**
            break;

以上代码的加粗部分就是。

再附上其他解决方法链接:http://nanjingjiangbiao-t.iteye.com/blog/1794478

你可能感兴趣的:(android)