AutoJs6 icon indicating copy to clipboard operation
AutoJs6 copied to clipboard

脚本获取的屏幕宽高不随屏幕旋转而变化 (Referenced)

Open SuperMonster003 opened this issue 2 years ago • 2 comments

js解决方案

let deviceClass = device.getClass();
let widthField = deviceClass.getDeclaredField("width");
let heightField = deviceClass.getDeclaredField("height");
widthField.setAccessible(true);
heightField.setAccessible(true);
widthField.setInt(device, context.getResources().getDisplayMetrics().widthPixels);
heightField.setInt(device, context.getResources().getDisplayMetrics().heightPixels);
let rotationListener = new JavaAdapter(android.view.OrientationEventListener, {
    onOrientationChanged: function (orientation) {
        widthField.setInt(device, context.getResources().getDisplayMetrics().widthPixels);
        heightField.setInt(device, context.getResources().getDisplayMetrics().heightPixels);
    }
}, context);
rotationListener.enable();

context.getResources().getDisplayMetrics().widthPixels 在AutoJs6中的结果反而是不变的, 不知道为什么. 讲道理这两个fork干脆合并算了

@SuperMonster003

Originally posted by @happyme531 in https://github.com/kkevsekk1/AutoX/issues/672#issuecomment-1731773848


context.getResources().getDisplayMetrics().widthPixels 正常情况下应该是随屏幕方向改变而变化的.

将于下一版本修复上述问题.

SuperMonster003 avatar Oct 12 '23 08:10 SuperMonster003

6.4.0 已尝试修复上述问题, 如问题复现, 可继续反馈.

SuperMonster003 avatar Nov 01 '23 12:11 SuperMonster003

问题已修复,感谢

happyme531 avatar Dec 20 '23 14:12 happyme531