如何数学计算Android屏幕宽高比 [英] How to calculate Android screen aspect ratio mathematically

查看:225
本文介绍了如何数学计算Android屏幕宽高比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android允许应用程序查询的设备屏幕属性之一是宽高比.在我看到的示例中,该属性似乎只有两个值- long notlong .

我正在尝试对Android用来将设备归类为具有两种长宽比之一的逻辑进行逆向工程.

要获取一些官方数据,我参考了Android Studio中AVD Manager工具中包含的设备定义所提供的值,并将其与我自己的计算相结合:

已发布比率"列显示了从AVD管理器中提取的值.根据这些结果,我无法理解Nexus 5和Nexus 6如何被认为 不长 ,而Galaxy S4和Galaxy Nexus被认为是 long 长> .

解决方案

DisplayMetrics metrics = context.getResources().getDisplayMetrics();
float ratio = ((float)metrics.heightPixels / (float)metrics.widthPixels
);

One of the device screen properties that Android lets an app query is it's aspect ratio. In the examples that I have seen this property seems to have only two values - long and notlong.

I am trying to reverse engineer the logic being used by Android to classify a device as having one of the two aspect ratios.

To get some official data to work with, I referred to the values provided by the device definitions included in the AVD Manager tool in Android Studio, and combined that with my own calculations:

The column "Published Ratio" shows the value extracted from the AVD Manager. Based on these results, I am failing to understand how Nexus 5 and 6 are considered notlong while Galaxy S4 and Galaxy Nexus are considered long.

解决方案

DisplayMetrics metrics = context.getResources().getDisplayMetrics();
float ratio = ((float)metrics.heightPixels / (float)metrics.widthPixels
);

这篇关于如何数学计算Android屏幕宽高比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆