如何以编程方式引发的Android触摸事件? [英] How to programmatically trigger the touch event in android?
本文介绍了如何以编程方式引发的Android触摸事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想触发触摸事件是这样的:
I would like to trigger a touch event like this:
第一手指触摸向下在(0.50%)的画面的画面和滑动到(50%,50%),以及出口(移动至手指离开画面)
First the finger is touch down at the (0,50%) of the screen and slide to the (50%,50%) of the screen, and exit (move the finger off the screen)
我已经发现了一些事情是这样的:
I have found some thing like this:
MotionEvent event = MotionEvent.obtain(downTime, eventTime, action, x, y, pressure, size, metaState, xPrecision, yPrecision, deviceId, edgeFlags);
onTouchEvent(event);
然而,如何效仿上述情况?我需要创建2的事件吗? onTouchDown,onMove等....?感谢您的帮助。
However, how to emulate the above case? Do I need to create 2 event ? onTouchDown , onMove etc.... ? Thanks for helping.
推荐答案
的可能重复:的如何在Android中模拟触摸事件?
// Obtain MotionEvent object
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis() + 100;
float x = 0.0f;
float y = 0.0f;
// List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
int metaState = 0;
MotionEvent motionEvent = MotionEvent.obtain(
downTime,
eventTime,
MotionEvent.ACTION_UP,
x,
y,
metaState
);
// Dispatch touch event to view
view.dispatchTouchEvent(motionEvent);
这篇关于如何以编程方式引发的Android触摸事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文