【问题标题】:MotionEvent with api 16 and Webview (Android)带有 api 16 和 Webview (Android) 的 MotionEvent
【发布时间】:2013-12-20 15:07:04
【问题描述】:

我想制作一个 MotionEvent 来控制一个 webiew。如果 api 低于 16 则一切正常:

 long downTime = SystemClock.uptimeMillis();
    long eventTime = SystemClock.uptimeMillis() + 500;
    float x = 50f;
    float y = 50f;
    // List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
    int metaState = 0;
    MotionEvent me = MotionEvent.obtain(
        downTime, 
        eventTime, 
        action, 
        x, 
        y, 
        metaState
    );

   view.dispatchTouchEvent(me);

但是 api 更高,然后我得到一个错误:源不是 SOURCE_CLASS_PIONTER。然后我把代码改成:

long downTime = SystemClock.uptimeMillis();
    long eventTime = SystemClock.uptimeMillis() + 500;
    float x = 50f;
    float y = 50f;
    // List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
    int metaState = 0;
    MotionEvent.PointerCoords p[] = null; 
    MotionEvent.PointerProperties p2[] = null;
  p[0] = new MotionEvent.PointerCoords();
p[0].x = x;
p[0].y = y;
p2[0] = new MotionEvent.PointerProperties();
p2[0].toolType = MotionEvent.TOOL_TYPE_FINGER;
p2[0].id = 0;
MotionEvent me =  MotionEvent.obtain(downTime, eventTime, action, 1, p2, p, metaState, 0, 1f, 1f, 0,0, 0, 0);
    view.dispatchTouchEvent(me);

但它不起作用。你有可以帮助我吗? 对不起,我的英语不好。

来自德国的问候。

【问题讨论】:

    标签: android webview motionevent


    【解决方案1】:
      MotionEvent me = MotionEvent.obtain(
            downTime, 
            eventTime, 
            action, 
            x, 
            y, 
            metaState
        );
        me.setSource(4098);
       view.dispatchTouchEvent(me);
    

    为我工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-08
      • 2017-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-14
      • 1970-01-01
      • 2012-10-08
      相关资源
      最近更新 更多