3

I am developing an android app where the user can take a photo. What I want to do is to give the user the ability to tag this photo. For example, they could touch the screen and tag that position as "shoes" or "head".

Is there a built-in way to get the pixel location when the user touches the screen (an API call for example or an event)? Or is there an easier way to do this?

Note: I am a complete beginner in Android development so please explain what's wrong with my question instead of just downvoting! That'd be so much more helpful.

George Eracleous
  • 4,278
  • 6
  • 41
  • 50
  • Hey George, did you end up coming up with a full solution to this? I'm stuck in the same position - need a simple arrow/circle image annotation - so any pointers would be absolutely fantastic. Thanks! – Joshua Pinter Mar 06 '15 at 01:32
  • Hey Josh. This question was posted a while ago and I have since abandoned that project so no solution! Sorry... – George Eracleous Mar 06 '15 at 09:18
  • No worries, George. I really appreciate you coming back to let me know, though. :) – Joshua Pinter Mar 07 '15 at 14:47

1 Answers1

8

You should first have a layout (say main.xml) that contains the photo as an ImageView:

<ImageView
    android:id="@+id/photo"
    android:src = "@+drawable/filename"
    android:background="@android:color/transparent"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
 />

Then use setOnTouchListener:

setContentView(R.layout.main);
ImageView mView = (ImageView) findViewById(R.id.photo);
mView.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            float x = event.getX();
            float y = event.getY();
        } 
});
Behzad Momahed Heravi
  • 1,383
  • 1
  • 12
  • 17