1. 程式人生 > >安卓模擬點選

安卓模擬點選

 //模擬點選
    public static  void setViewonlick(View view,float X,float Y){

        long downTime= SystemClock.uptimeMillis();
        MotionEvent dowmEvent=MotionEvent.obtain(downTime,downTime,MotionEvent.ACTION_DOWN,X,Y,0);
        downTime+=1000;
        MotionEvent upEvent=MotionEvent.obtain(downTime,downTime,MotionEvent.ACTION_UP,X,Y,0);
        view.onTouchEvent(dowmEvent);
        view.onTouchEvent(upEvent);

        dowmEvent.recycle();
        upEvent.recycle();

    }