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 6875539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:20:36+00:00 2026-05-27T04:20:36+00:00

I have an image in ImageView. I need to know the exact (x,y) coordinate

  • 0

I have an image in ImageView. I need to know the exact (x,y) coordinate of the image when I touch the image. I also want to draw a circle on the touch place.

Given below, is the code I use. I have an ImageView and I attach a onTouchListener to it.

The problem is this:

  1. I get weird (x,y) values
  2. new circles are only drawn 3 times. After that no new circles are drawn!

    ImageView touch=(ImageView) findViewById(R.id.image);
    touch.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN){
    
               //Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
               //Canvas can=new Canvas(bm);
               p.setColor(Color.RED);
               float fx=event.getX();
               float fy=event.getY();
               can.drawCircle(fx, fy, 20, p);                   
            }
            return true;
        }
    });
    
  • 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-27T04:20:37+00:00Added an answer on May 27, 2026 at 4:20 am

    The problem is most likely that you aren’t taking into account the fact that the position of the MotionEvent is adjusted to be relative to the containing view (the ImageView in this case) and it looks like you are attempting to draw them on another Canvas which would have a different coordinate space. If you need the two to be separate like this, I would recommend using MotionEvent.getRawX() and MotionEvent.getRawY() so that the touch values are in the coordinates of the screen as a whole.

    However, if you just want to draw the circles over the image, a better solution would be to subclass ImageView so you can detect touches in its onTouchEvent() method directly (instead of a listener) and do custom drawing in its onDraw() method, guaranteeing everything is in the same adjusted coordinate plane.

    It is not apparent from your code why this operation would only work correctly three times. Perhaps try only returning true from the touch detection method in the DOWN instance that you are interested in. You may be unnecessarily stealing touch events with the current implementation.

    HTH

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

Sidebar

Related Questions

I need a way to have a gray scale image in an ImageView and
I need to know which image is in which cell, so I have only
I have following Image as src in ImageView. I use this as background image.
I have a problem when inserting an image in an ImageView. I have tried
I have a problem with UIButton image if I set its imageView contentMode to
In my xml file, I have declared two imageview and later I add image
I want to show an image view for three like on/off,if any one have
I put an image inside an ImageView and have multitouch implemented to resize and
I have a listview which includes 2 textviews and 1 imageview. Now, the image
I have this setting below, but when I touch the table cell, I get

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.