回答
要使用控件的所有信息获取边距并点击中心坐标,你可以按照以下步骤操作:
- 首先通过选择器找到目标控件
- 使用bounds()方法获取控件的边界信息
- 通过Rect对象的centerX()和centerY()方法获取中心坐标
- 使用click()函数点击该坐标
示例代码:
// 文档地址 https://docs.hamibot.com/
// 获取文本为"确定"的按钮并点击其中心
var button = text("确定").findOne();
var bounds = button.bounds();
// 显示边界信息(可选)
toast("左:" + bounds.left + ", 上:" + bounds.top +
", 右:" + bounds.right + ", 下:" + bounds.bottom);
// 点击控件中心
click(bounds.centerX(), bounds.centerY());
// 如果需要root权限点击,可以使用:
// Tap(bounds.centerX(), bounds.centerY());
// 也可以直接一步完成:
// click(text("确定").findOne().bounds().centerX(),
// text("确定").findOne().bounds().centerY());
Rect对象提供了以下有用的属性和方法:
- left: 控件左边缘X坐标
- top: 控件上边缘Y坐标
- right: 控件右边缘X坐标
- bottom: 控件下边缘Y坐标
- centerX(): 返回控件中心X坐标
- centerY(): 返回控件中心Y坐标
- width(): 返回控件宽度
- height(): 返回控件高度
如果脚本需要在不同分辨率设备上运行,记得使用setScreenMetrics()设置设计时的分辨率,这样坐标会自动适配。
ℹ️ 本回答由 AI 生成,内容仅供参考