简体   繁体   English

计算器应用在同一屏幕尺寸上但DPI不同(420 DPI与480 DPI)的布局不同

[英]Calculator app different layout on same screen size but different DPI (420 DPI vs 480 DPI)

I have made this very simple calculator layout. 我已经做了一个非常简单的计算器布局。 But its different for 480 DPI and 420 DPI on my phone. 但是我的手机上480 DPI和420 DPI有所不同。 There is free space on right part of screen in 420DPI and buttons are thinner than 480DPI. 420DPI的屏幕右侧有可用空间,并且按钮比480DPI细。 I used dp as a units of measurements for buttons and sp for text. 我将dp用作按钮的度量单位,将sp用作文本的度量单位。

I read Supporting Different Screen Sizes | 我阅读了支持不同的屏幕尺寸| Android Developers but couldn't really solve my problem. Android开发人员,但无法真正解决我的问题。

I have read that dp unit is independent of DPI of the screen and buttons will scale up or down dynamically. 我已经读过dp单位与屏幕的DPI无关,并且按钮会动态缩放。 Then how come my buttons get thinner on different DPI even after i used dp as an unit? 那么,即使我以dp为单位,在不同的DPI上我的按钮又如何变细呢?

I put a file in res folder, the file name is values-w410dp ,because Nexus 5X 1920 x 1080 px (730 x 410 dp) normal 420 dpi. 我将文件放在res文件夹中,文件名为values-w410dp,因为Nexus 5X 1920 x 1080 px(730 x 410 dp)正常为420 dpi。

You can try. 你可以试试。 It can control layout. 它可以控制布局。

You need to have multiple layout folders in res . 您需要在res中具有多个布局文件夹。 Name one of them layout-xxhdpi and put your layout xml there. 将其中之一命名为layout-xxhdpi ,然后将布局xml放在此处。 Devices with density >= 480dpi will load layouts from this folder. 密度> = 480dpi的设备将从该文件夹加载布局。 Another layout folder should be named layout . 另一个布局文件夹应命名为layout Devices with density lower than 480dpi will load layouts from layout . 密度低于480dpi的设备将从布局中加载布局。 In order to support multiple screens, layouts must have same ID in both folders. 为了支持多个屏幕,布局在两个文件夹中必须具有相同的ID。 You can read more about resource qualifiers here http://developer.android.com/guide/topics/resources/providing-resources.html 您可以在http://developer.android.com/guide/topics/resources/providing-resources.html上了解有关资源限定符的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM