android 7.0中引入新的手势api,它在
AccessibilityService中实现
public final boolean dispatchGesture(@NonNull GestureDescription gesture,
@Nullable GestureResultCallback callback,
@Nullable Handler handler)
要使用它很简单,首先声明一个Path:
Path path = new Path(); path.moveTo(100, 500); //点击(100,500)做为起点 path.lineTo(800,500); //水平向右滑动到(800,500)
再创建一个GestureDescription,添加上面的路径,最多可以添加10个路径,实现多段滑动
GestureDescription.Builder builder = new GestureDescription.Builder();
GestureDescription description = builder.addStroke(
new GestureDescription.StrokeDescription(path, 20L, 1000L)).build();
boolean ret=mAccService.dispatchGesture(description,
new AccessibilityService.GestureResultCallback() {
@Override
public void onCompleted(GestureDescription gestureDescription) {
super.onCompleted(gestureDescription);

本文介绍了Android 7.0中新增的手势API,包括如何通过Path和GestureDescription.Builder实现滑动手势,以及如何在AccessibilityService中使用dispatchGesture方法来触发手势,并解决了XML配置中的常见问题。
1150

被折叠的 条评论
为什么被折叠?



