天天看点

android 模拟点击2

MotionEvent me=MotionEvent.obtain(0,0,MotionEvent.ACTION_DOWN,x,y,0);

onTouch(mPageWidget, me);

可用Instrumentation 模拟触摸时间

例如触摸点(240,400):

Instrumentation inst=new Instrumentation();

inst.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 240, 400, 0));

inst.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 240, 400, 0));

继续阅读