[英]How to create custom dimen files for same DPI bucket devices?
I am writing an Android game and I am testing it in two devices at the same time:我正在编写一个 Android 游戏,并同时在两个设备上对其进行测试:
These two devices are utterly different, as they differ in screen size and resolution , but NOT in dpi and dpi bucket;这两种设备完全不同,因为它们的屏幕尺寸和分辨率不同,但在 dpi 和 dpi 桶上却没有; both are xhdpi .两者都是 xhdpi 。
That means regardless the dimen files I create (dimen-mdpi, dimen-hdpi...), any graphic element looks the same in both phones, which completely breaks the layout and proportions in the small phone .这意味着无论我创建什么尺寸文件(dimen-mdpi、dimen-hdpi...),任何图形元素在两部手机中看起来都是一样的,这完全破坏了小手机中的布局和比例。
I'm taking this as a reference for bucket classification:我将此作为存储桶分类的参考:
Well dpi is all about resolution, and not screen size. dpi 是关于分辨率的,而不是屏幕尺寸。 If you want to create resources for screen sizes, and not screen resolutions, you should use smalest width qualifiers .如果你想为屏幕尺寸而不是屏幕分辨率创建资源,你应该使用smalest width qualifiers 。
One DIP is one pixel on an approximately 160 dpi screen (for example a 240x320, 1.5"x2" screen), providing the baseline of the system's display.一个 DIP 是大约 160 dpi 屏幕(例如 240x320、1.5"x2" 屏幕)上的一个像素,提供系统显示的基线。 Thus on a 160dpi screen this density value will be 1;因此,在 160dpi 屏幕上,此密度值为 1; on a 120 dpi screen it would be.75;在 120 dpi 的屏幕上,它将是.75; etc.等等
So if I understand correctly, you would convert from pixel to dp
by: pixelSize / dip / 160
.因此,如果我理解正确,您可以通过以下方式从像素转换为dp
: pixelSize / dip / 160
。 In this case the formula for your device width in dp is as follows: deviceWidthInPixels / (deviceDip / 160)
.在这种情况下,以 dp 为单位的设备宽度公式如下: deviceWidthInPixels / (deviceDip / 160)
。
Looks like other people also came to this conclusion貌似其他人也得出了这个结论
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.