android 模拟用户点击事件
模拟用户点击事件
private void setSimulateClick(View view, float x, float y) { long downTime = SystemClock.uptimeMillis(); final MotionEvent downEvent = MotionEvent.obtain(downTime, downTime,MotionEvent.ACTION_DOWN, x, y, 0); downTime += 1000; final MotionEvent upEvent = MotionEvent.obtain(downTime, downTime,MotionEvent.ACTION_UP, x, y, 0); view.onTouchEvent(downEvent);view.onTouchEvent(upEvent);downEvent.recycle(); upEvent.recycle();}