本文介绍了模拟Android的手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何模拟手势编程。

How can I simulate gestures programmatically.

我得到的所有的点,我想我的应用程序重复这些图纸。

I get all the points and I would like my app to repeat these drawings.

public void onGestureStarted(GestureOverlayView gestureOverlayView, MotionEvent motionEvent) {
            Log.d("TAG", "Started gesture: \n" + motionEvent.getRawX() + "\n" +
                    motionEvent.getRawY() + "\n" + motionEvent.getEventTime());

            gestures.add(new GesturePoint(motionEvent.getRawX(), motionEvent.getRawY(), 100));
        }

        @Override
        public void onGesture(GestureOverlayView gestureOverlayView, MotionEvent motionEvent) {
            //To change body of implemented methods use File | Settings | File Templates.
            gestures.add(new GesturePoint(motionEvent.getRawX(), motionEvent.getRawY(), 100));
            Log.e("TAG", "gesture: \n" + motionEvent.getRawX() + "\n" +
                    motionEvent.getRawY() + "\n" + motionEvent.getEventTime());
        }

        @Override
        public void onGestureEnded(GestureOverlayView gestureOverlayView, MotionEvent motionEvent) {
            gestures.add(new GesturePoint(motionEvent.getRawX(), motionEvent.getRawY(), 100));

            Log.d("TAG", "Ended gesture: \n" + motionEvent.getRawX() + "\n" +
                    motionEvent.getRawY() + "\n" + motionEvent.getEventTime());

            g.addStroke(new GestureStroke(gestures));
            gestureOverlayView.setGesture(g);

有没有像startDraw(ArrayList的)?

Is there any method like startDraw(Arraylist)?

我需要它来模拟用户交互。

i need it to simulate user interaction.

推荐答案

您可以使用的 MotionEvent 的类。使用简单:

You can use MotionEvent class. Simple use:

MotionEvent emulateActionDown = MotionEvent.obtain
(
    // The time (in ms) when the user originally pressed down to start a stream of position events.
    // This must be obtained from uptimeMillis().
    SystemClock.uptimeMillis(),
    // The the time (in ms) when this specific event was generated.
    // This must be obtained from uptimeMillis().
    SystemClock.uptimeMillis()+20,
    // The kind of action being performed, such as ACTION_DOWN.
    MotionEvent.ACTION_DOWN,
    // The X coordinate of this event.
    1,
    // The Y coordinate of this event.
    1,
    // The state of any meta / modifier keys that were in effect when the event was generated.
    0
)

给出一个ACTION_DOWN仿真。然后,您可以将此事件传递给的 onTouchEvent 的视图的方法:

myView.onTouchEvent(emulateActionDown);

在这里看看: MotionEvent - >获得

这篇关于模拟Android的手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 14:18