1

So, I need to get coordinates of my touch on ImageView.

I have already successfully tried to get coordinates in OnTouchListener event. 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.

How to get actual coordinates (maybe certain pixels) of the image?

Dmitry Ushkevich
  • 392
  • 2
  • 14

2 Answers2

2

There's getLocationOnScreen() and getLocationInWindow() methods for the purpose.

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;
            }
        });
Fatih Santalu
  • 4,641
  • 2
  • 17
  • 34
2

Android: How do I get the x y coordinates within an image / ImageView?

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?

Suhail Purkar
  • 104
  • 14