让所有的X和Y坐标是针对Android移动事件 [英] Getting All x and y coordinates from a motion event in android

查看:140
本文介绍了让所有的X和Y坐标是针对Android移动事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在对我自己基本的绘图应用程序。到目前为止,我的应用程序工作良好,但我注意到,我的议案的事件似乎并没有得到所有被感动的X和Y轴点。

I'm currently working on my own basic drawing app. So far, my app is working well but I noticed that my motion event doesn't seem to get all the X and Y axis points that are touched.

当我在屏幕上移动我的手指,有圆之间显着的空间。只有当我移动我的手指慢慢地做它捕获所有的点。有没有一种方法可以让我抓住所有的点还是有办法可以优化它能够处理所有的点?

When I move my finger across the screen, there is noticeable spaces between the circles. Only when I move my finger slowly does it capture all the points. Is there a way I can grab all the points or is there a way i can optimize it to be able to handle all the points?

下面就是我正在做的:

setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {

                int x; 
            int y;    

            switch (event.getAction())
            {
                case MotionEvent.ACTION_DOWN:
                {
                    x = (int) event.getX();
                    y = (int) event.getY();   
                    //method draws circle at x and y coordinate
                    MyPainter mp = new MyPainter(x,y);

                    break;
                }
                case MotionEvent.ACTION_MOVE:
                {
                    x = (int) event.getX();
                    y = (int) event.getY();
                MyPainter mp = new MyPainter(x,y);

                    break;
                }
            }
            return true;

        }
    });

任何建议或意见都AP preciated。谢谢

Any Suggestions or comments are appreciated. Thanks

推荐答案

这仅仅是硬件的设计方式。硬件采样每秒触摸屏N次,每次它检测手指时吐出的坐标。

This is just the way the hardware is designed. The hardware samples the touchscreen N times per second, and spits out the coordinates every time it senses a finger.

如果你移动超过屏幕的样本更快,你就必须在报告的数据空白。唯一可以做的事情是沿着两个触摸之间的线内插自己产生失分。

If you move faster than the screen samples, you'll have gaps in the reported data. Only thing you can do is to generate the missing points yourself by interpolating along the line between the two touches.

这篇关于让所有的X和Y坐标是针对Android移动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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