android 模拟ACTION_HOVER_MOVE
时间: 2023-07-24 22:30:54 浏览: 278
Android 平台上模拟 ACTION_HOVER_MOVE 可以使用 MotionEvent 类中的 MotionEvent.ACTION_HOVER_MOVE 常量来创建 MotionEvent 对象,具体步骤如下:
1. 创建 MotionEvent 对象:
```
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis() + 100;
float x = 200;
float y = 200;
int metaState = 0;
MotionEvent motionEvent = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_HOVER_MOVE, x, y, metaState);
```
2. 发送 MotionEvent 事件:
```
view.dispatchTouchEvent(motionEvent);
```
其中,downTime 表示手指按下的时间,eventTime 表示手指移动的时间,x 和 y 表示手指移动的坐标,metaState 表示手指的元状态,view 表示要模拟事件的视图。
通过反复发送 MotionEvent 对象,即可模拟 ACTION_HOVER_MOVE 的效果。需要注意的是,模拟 ACTION_HOVER_MOVE 事件必须在支持悬停的设备上才能生效,否则将不会有任何效果。
相关问题
android 模拟 hover move
Android 平台上模拟 hover move 可以使用 MotionEvent 类来模拟手指移动的事件,具体步骤如下:
1. 创建 MotionEvent 对象:
```
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis() + 100;
float x = 200;
float y = 200;
int metaState = 0;
MotionEvent motionEvent = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, x, y, metaState);
```
2. 发送 MotionEvent 事件:
```
view.dispatchTouchEvent(motionEvent);
```
其中,downTime 表示手指按下的时间,eventTime 表示手指移动的时间,x 和 y 表示手指移动的坐标,metaState 表示手指的元状态,view 表示要模拟事件的视图。
通过反复发送 MotionEvent 对象,即可模拟 hover move 的效果。需要注意的是,如果要模拟手指的按下和抬起事件,需要分别使用 MotionEvent.ACTION_DOWN 和 MotionEvent.ACTION_UP 来创建 MotionEvent 对象,并发送到视图中。
阅读全文
相关推荐












