如何解决如何在Android中使手势描述可访问性连续向下滑动手势滚动
我正在尝试使用具有辅助功能的手势描述来连续向下滚动。这是我的向下滑动代码
val displayMetrics = resources.displayMetrics
val height : Int = displayMetrics.heightPixels;
val top : Float = height*0.25.toFloat()
val bottom :Float = height *0.75.toFloat()
val swipePath = Path()
swipePath.moveTo(top,bottom)
swipePath.lineTo(top,top)
val gestureBuilder = GestureDescription.Builder()
gestureBuilder.addStroke(GestureDescription.StrokeDescription(swipePath,1000))
dispatchGesture(gestureBuilder.build(),null,null)
请帮助。
解决方法
path.moveTo()
和path.lineTo()
都接受两个参数,分别是x和y坐标,并且要垂直滑动起点和终点的x坐标应该相同。您从高度而不是宽度获取x坐标,这可能还会产生其他问题,例如屏幕外的点。所以我修改了一点代码
val displayMetrics = resources.displayMetrics
val height : Int = displayMetrics.heightPixels
val xCenter: Float = displayMetrics.widthPixels.toFloat()/2
val top : Float = height*0.25.toFloat()
val bottom :Float = height *0.75.toFloat()
val swipePath = Path()
swipePath.moveTo(xCenter,bottom)
swipePath.lineTo(xCenter,top)
val gestureBuilder = GestureDescription.Builder()
gestureBuilder.addStroke(GestureDescription.StrokeDescription(swipePath,1000))
dispatchGesture(gestureBuilder.build(),null,null)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。