首页 > 解决方案 > 在不同时间在一个图像视图中进行多点触控 Android Studio

问题描述

我正在尝试处理图像上的用户触摸侦听器,我想存储触摸像素的图像视图的所有 XY 坐标。作为这个图像,senario:用户在第一次触摸时触摸图像,我想存储 XY 坐标,然后用户在第二次触摸时触摸相同的图像,我也想存储 XY 坐标等等。手机屏幕

标签: androidtouch-event

解决方案


希望对您有所帮助!

public class Coordinate {
        float x;
        float y;

        public Coordinate(float x, float y) {
            this.x = x;
            this.y = y;
        }
}

ArrayList<Coordinate> coordinates = new ArrayList<>();

yourImageView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                //int eventAction = event.getAction();
                //switch (eventAction) {
                //    case MotionEvent.ACTION_DOWN:                            
                //        break;
                //    case MotionEvent.ACTION_UP:
                //        break;
                //    case MotionEvent.ACTION_MOVE:
                //      break;
                //}
                coordinates.add(new Coordinate(event.getX(), event.getY()));
                return false;
            }
        });

推荐阅读