如何显示在触摸事件图像十字标记? [英] How to display cross mark in images on touch event?

查看:114
本文介绍了如何显示在触摸事件图像十字标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目有一个形象。当用户触摸在图像中的任何地方,应当用十字标记符号。此外,我们要明确一个按钮点击这个十字架。我设法显示图像。我有什么在 ontouchlistener()函数来显示交叉点呢?请帮助。

In my project there is an image. When the user touches any place in the image, it should be marked with a cross sign. Also we have to clear this cross on a button click. I managed to display the image. What do I have to do in the ontouchlistener() function to display the cross point? Please help.

推荐答案

我将创建一个自定义的的ImageView ,是这样的:

I would create a custom ImageView, something like:

public class MarkableImageView extends ImageView {

    ArrayList<Marker> mMarkers;

    // ...

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        for(Marker m : mMarkers) {
            // draw the marker
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent e) {
        if (e.getAction() == MotionEvent.ACTION_DOWN) {
            mMarkers.add(new Marker(e.getX(), e.getY()));
            invalidate();
            return true;
        }
        return false;
    }

    public void reset() {
        mMarkers.clear();
        invalidate();
    }

    // this class will be visible only inside MarkableImageView
    private class Marker {
        public int x;
        public int y;
        // you might want to add other properties, for example
        // if you need to have different types of markers

        public Marker(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
}

这篇关于如何显示在触摸事件图像十字标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆