我创建了 layout-sw600dp/layout.xml,它在设备 A 上看起来很棒。但是在设备 B 上,这个布局已经融化并且看起来很糟糕。我想知道我的布局在最坏情况下的外观(正好 600dp 宽度的屏幕)
我想创建具有该屏幕尺寸的模拟器,因此我将 100% 确定我的布局在 sw-600dp+ 手机上看起来不错。你知道它的尺寸吗?
此外,如果您能给我建议如何在现代世界中支持多种屏幕尺寸,我将非常感激和高兴。
附言我有 40 多个按钮的非常困难的布局
最佳答案
关于您将用于 sw-600dp+ 的模拟器类型的问题的简短回答:7"平板电脑。您可以找到更多信息 here。 中的
是sw
sw-600dp最小宽度
限定符。这意味着它仅适用于具有 600dp 的设备,通常是 7"平板电脑。
关于如何确保您的应用在“现代世界”中看起来不错的问题的较长答案是:
与其试图弄清楚什么是“最坏情况”,您应该为每种不同的屏幕密度和设备类型设计布局 Android supports :
- ldpi Resources for low-density (ldpi) screens (~120dpi).
- mdpi Resources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.)
- hdpi Resources for high-density (hdpi) screens (~240dpi).
- xhdpi Resources for extra-high-density (xhdpi) screens (~320dpi).
- xxhdpi Resources for extra-extra-high-density (xxhdpi) screens (~480dpi).
- xxxhdpi Resources for extra-extra-extra-high-density (xxxhdpi) uses (~640dpi).
根据 Android docs :
To create alternative bitmap drawables for different densities, you should follow the 3:4:6:8:12:16 scaling ratio between the six primary densities. For example, if you have a bitmap drawable that's 48x48 pixels for medium-density screens, all the different sizes should be:
36x36 (0.75x) for low-density (ldpi) 48x48 (1.0x baseline) for medium-density (mdpi) 72x72 (1.5x) for high-density (hdpi) 96x96 (2.0x) for extra-high-density (xhdpi) 144x144 (3.0x) for extra-extra-high-density (xxhdpi) 192x192 (4.0x) for extra-extra-extra-high-density (xxxhdpi) Then, place the generated image files in the appropriate subdirectory under res/ and the system will pick the correct one automatically based on the pixel density of the device your app is running on:
res/ drawable-xxxhdpi/ awesome-image.png drawable-xxhdpi/ awesome-image.png drawable-xhdpi/ awesome-image.png drawable-hdpi/ awesome-image.png drawable-mdpi/ awesome-image.png
您可以对布局做同样的事情,为每个不同的维度创建一个特定的布局(确保将布局放在正确的目录中:layout-xhdpi、layout-mdpi 等)。这样做将允许设备根据用户使用的设备选择正确的图像/布局。
如果您有一个超过 40 个按钮的布局,您可以使用上述方法为每个布局创建按钮,然后为每个设备创建布局。这是一项繁琐的工作,但这是在 Android 设备上进行布局的正确方法。
TLDR;阅读 Android documents around supporting multiple screen sizes .
关于android - 使用 sw-600dp 布局的最小屏幕尺寸是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64855378/