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();}

 

posted on 2020-03-21 14:57  lvlv岁月流逝  阅读(924)  评论(0编辑  收藏  举报

导航