简体   繁体   中英

Tag photos on Android app

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.

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();
        } 
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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