android - 根据屏幕尺寸转换 X 和 Y 像素

标签 android math screen

我在屏幕分辨率为720 x 1280的手机中使用此命令input tap x y(input tap 600 500),该怎么做我转换了 x y,因此它在分辨率为 1080 x 1920 的手机中将处于同一点。谢谢

最佳答案

此伪代码应该可以为您提供所需的值:

resolution_width = 720;
resolution_height = 1280;

input_x = 600;
input_y = 500;

target_width = 1080;
target_height = 1920;

percent_width = input_x / resolution_width;
percent_height = input_y / resolution_height;

output_x = target_width * percent_width;
output_y = target_height * percent_height;

关于android - 根据屏幕尺寸转换 X 和 Y 像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21581265/

相关文章:

android - Ionic Android 内部共享内存

c - 代码中 2*2 矩阵的非平凡特征向量

android - 多屏幕支持完整性检查

android - 为什么这段通过 GPS 获取位置的代码不起作用?

android - Flutter 依赖项不起作用

Javascript 数学效率舍入

android - 如何获得手机相对于地球磁场的角度?

android - 如何在android上处理不同尺寸的屏幕

android - 阻止 xlarge 屏幕 android

Android SelectableItemBackground 不工作