简体   繁体   English

在ImageView touch上获取X / Y坐标

[英]Get X/Y coordinates on ImageView touch

So, I need to get coordinates of my touch on ImageView. 因此,我需要获取ImageView上的触摸坐标。

I have already successfully tried to get coordinates in OnTouchListener event. 我已经成功尝试在OnTouchListener事件中获取坐标。 But it is not what i really need. 但这不是我真正需要的。

The problem is that the resolution of the screen is much lower than the resolution of the picture in ImageView. 问题在于屏幕的分辨率远低于ImageView中图片的分辨率。

How to get actual coordinates (maybe certain pixels) of the image? 如何获得图像的实际坐标(可能是某些像素)?

There's getLocationOnScreen() and getLocationInWindow() methods for the purpose. 有用于此目的的getLocationOnScreen()和getLocationInWindow()方法。

imageView.setOnTouchListener(new OnTouchListener() {
            @Override public boolean onTouch(View view, MotionEvent motionEvent) {
                int[] locations = new int[2];
                view.getLocationOnScreen(locations);
                //view.getLocationInWindow(locations);
                return false;
            }
        });

Android: How do I get the xy coordinates within an image / ImageView? Android:如何获取图像/ ImageView中的xy坐标?

imageView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            int[] values = new int[2]; 
            view.getLocationOnScreen(values);
            Log.d("X & Y",values[0]+" "+values[1]);
        }
    });

Something like this? 像这样吗

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM