Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6916675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:38:00+00:00 2026-05-27T09:38:00+00:00

I have an image I am displaying to a user in my android application.

  • 0

I have an image I am displaying to a user in my android application.

I want to be able to tell where they ‘touch’ the image.

I can easily get the screen coordinates by implementing an OnTouchListener

 private OnTouchListener image_Listener = new OnTouchListener(){
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_UP) {
            float x = event.getX();
            float y = event.getY();
            return true;
        }
        return false;
    }
};

However, these are absolute coordinates. What I really need is a function to convert this into coordinates relative to a View..

I have done a bit of digging, but I can’t seem to turn up anything, aside from me trying to implement a ScreenToClient method myself..

Does anyone know of a good solution to this, or am I just going to have to roll my own?

It seems like the kind of method that would be available – that’s why I’m asking.

Thank you all for your time.

EDIT: I’m not so sure that the coordinates aren’t already relative to the view. I could have swore reading that coordinates were absolute, but after some tinkering – I have things working as I expected.. Sorry for the noise guys.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:38:01+00:00Added an answer on May 27, 2026 at 9:38 am

    Just to answer, the touches are relative to view in a way. Yes, they are raw screen coordinates of the touch. However, since you register the touch event to the view itself, it will only fire if the user actually touches the view. That means, even though the screen coordinates are raw screen coordinates, they are within the bounds of the view itself.

    If you want to get the x/y coordinates of the touched view in relation to only itself, then you can subract the left coordinate with the screen coordinate and the top coordinate from the y coordinate like so:

    private OnTouchListener image_Listener = new OnTouchListener(){
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if(event.getAction() == MotionEvent.ACTION_UP) {
                float screenX = event.getX();
                float screenY = event.getY();
                float viewX = screenX - v.getLeft();
                float viewY = screenY - v.getTop();
                return true;
            }
            return false;
        }
    };
    

    With that, if the user touched 40 x-pixels down the screen, but the left margin was set to 10, then viewX would be 30. If you moved the view down 40 x-pixels and the user touched the same spot in the view, it would still be 30.

    It gets slightly more complicated if you included padding as padding within a View still counts as a View even though it doesn’t display anything.

    EDIT:

    I should point out that what Pierre said is true. If you touch a view, then it will continue to receive touch events until the finger is lifted even if you drag your finger outside the view bounds. This means, ACTION_UP can receive touch coordinates for your view that are not within the bounds.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have image data and i want to get a sub image of that
So I have Image like this (source: de-viz.ru ) I want to get something
So I have Image like this (source: de-viz.ru ) I want to get something
I have displaying image thumbnails in a UIScrollView , if user taps on a
I am uploading a user image in mvc2 web application. User can upload an
I have: image 1:Many imageToTag Many:1 tag I want to issue a query that
The issue is I have a link Onclick of that user will get a
I have a variety of image sets that I'm displaying on a web page
My problem is that I have a user that is having a problem displaying
Basically I want to take an image that the user chooses from their photo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.