1

我正在使用https://github.com/MikeOrtiz/TouchImageView中的 TouchImageView ,我正在尝试使用高光。例如,当用户点击图像的某个点时(无论图像是否放大都无关紧要),我会触发一个事件 - 在 webview 中显示突出显示的描述。它有效,但只有当所有图像都适合视图时,当我放大所有错误时。if (scaledRight < 0) 它似乎工作得相当好,但是当它落在 else 上时它就不起作用了。任何帮助将不胜感激,如果有效,我可以将其发送给创建者:) 提前致谢。

public boolean onTouch(View v, MotionEvent event) { mScaleDetector.onTouchEvent(event);

            matrix.getValues(m);
            float x = m[Matrix.MTRANS_X];
            float y = m[Matrix.MTRANS_Y];

            PointF curr = new PointF(event.getX(), event.getY());

            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    last.set(event.getX(), event.getY());

                    if(!isFullScreen){
                        //System.out.println("Right is " + right);
                        //System.out.println("Bottom is " + bottom);
                        //System.out.println("Start x is " + start.x);
                        //System.out.println("Start y is " + start.y);

                        //float scaledRight = 2 * (right);
                        float scaledRight = 2 * (right/saveScale);
                        float scaledBottom = 2 * (bottom/saveScale);
                        //float scaledBottom = 2 * (bottom);

                        float tapPositionX = 0;
                        float tapPositionY = 0;

                        double xMaxBound = 0;
                        double xMinBound = 0;
                        double yMaxBound = 0;
                        double yMinBound = 0;                       
                        int radius = 0;

                        System.out.println("Right is " + right);
                        System.out.println("Bottom is " + bottom);
                        /*
                        if(theDeltaX < 0) {
                            theDeltaX = -theDeltaX;
                        }
                        theDeltaX = theDeltaX / saveScale;

                        if(theDeltaY < 0) {
                            theDeltaY = -theDeltaY;
                        }
                        theDeltaY = theDeltaY / saveScale;     
                        */


                        for(int i = 0; i < XMLParser.hlPicIDArray.size(); i++)
                        {
                            if(imageID.equalsIgnoreCase(XMLParser.hlPicIDArray.get(i))) {

                                radius = Integer.parseInt(XMLParser.hlRadiusArray.get(i));
                                xMaxBound = Integer.parseInt(XMLParser.hlOrXArray.get(i));
                                xMinBound = xMaxBound;
                                yMaxBound = Integer.parseInt(XMLParser.hlOrYArray.get(i));
                                yMinBound = yMaxBound;
                                xMaxBound = xMaxBound + (radius * Math.cos(0));
                                xMinBound = xMinBound + (radius * Math.cos(3.14));
                                yMaxBound = yMaxBound + (radius * Math.sin(1.57));
                                yMinBound = yMinBound + (radius * Math.sin(4.71));

                                if(scaledRight <= 0) {
                                    //tapPositionX = (bmWidth * 2) - (scaledRight) + (80/saveScale);
                                    tapPositionX = bmWidth - (scaledRight) + (80/saveScale);
                                    tapPositionX = (curr.x/width) * (tapPositionX);
                                    tapPositionX += (right);// - 80;
                                    xMinBound = xMinBound - (0.12 * xMinBound); //Compensation for imprecision
                                    //xMaxBound = xMaxBound - (0.08 * (maxScale - saveScale) * xMinBound); 
                                    //Highlight point is added to right to compensate the white margins
                                }
                                else {
                                    //?
                                    //tapPositionX = (start.x/width) * right * 2; //(+ offset)
                                    tapPositionX = (start.x/width) * right; //(+ offset)
                                    //tapPositionX = tapPositionX + ((theDeltaX/width) * bmWidth * 2);
                                    tapPositionX = tapPositionX + (last.x/width) * (bmWidth - right); // * 2
                                    //tapPositionX -= theDeltaX;
                                }

                                if(scaledBottom <= 0) {
                                    //tapPositionY = (bmHeight * 2) - (scaledBottom) + (80/saveScale);
                                    tapPositionY = bmHeight - (scaledBottom) + (80/saveScale);
                                    tapPositionY = (last.y/height) * tapPositionY;
                                    tapPositionY += (bottom/saveScale);// - 80;
                                    yMinBound = yMinBound - (0.12 * yMinBound); //Compensation for imprecision
                                    //yMaxBound = yMaxBound - (0.08 * (maxScale - saveScale) * yMinBound); 
                                }
                                else {
                                    //tapPositionY = (start.y/height) * bottom * 2;
                                    tapPositionY = (start.y/height) * bottom;
                                    tapPositionY = tapPositionY + (last.y/height) * (bmHeight - bottom);
                                    //tapPositionY -= theDeltaY;
                                }

                                System.out.println("X tapped is " + tapPositionX);
                                System.out.println("Y tapped is " + tapPositionY);
                                System.out.println("Delta X is " + theDeltaX);
                                System.out.println("Delta Y is " + theDeltaY);


                                if((tapPositionX <= xMaxBound) && (tapPositionX >= xMinBound) && (tapPositionY <= yMaxBound) && (tapPositionY >= yMinBound)) {
                                    System.out.println("HL Area tapped!");
4

0 回答 0