简体   繁体   English

如何在Android上支持不同的屏幕尺寸和不同的密度

[英]How to support different screens sizes AND different densities on Android

I know about <resources_name>-<qualifier> naming convention for resources in Android and how to use them for screen sizes (eg <drawable_xLarge> ) or screen densities (eg <drawable xhdpi> ). 我知道Android中资源的<resources_name>-<qualifier>命名约定,以及如何将它们用于屏幕尺寸(例如<drawable_xLarge> )或屏幕密度(例如<drawable xhdpi> )。

I want to know, how to handle the case of supporting different densities for each screen size variation there is. 我想知道,对于每种屏幕尺寸变化,如何处理支持不同密度的情况。 Ie

<drawable-xlarge>
    <drawable-xhpdi>
    <drawable-hpdi>
    <drawable-mpdi>
    <drawable-lpdi>

<drawable-large>
    <drawable-xhpdi>
    <drawable-hpdi>
    <drawable-mpdi>
    <drawable-lpdi>
...

Can any one enlighten me please? 有人能启发我吗? Cheers 干杯

This is a very complicated question. 这是一个非常复杂的问题。 There is a very good explanation in the documentation you should check. 您应该检查的文档中有很好的解释。

http://developer.android.com/guide/practices/screens_support.html http://developer.android.com/guide/practices/screens_support.html

Otherwise, your question is way too open ended. 否则,您的问题太开放了。

The specific paragraph you will find in the docs is: 您将在文档中找到的特定段落是:

Provide different layouts for different screen sizes 为不同的屏幕尺寸提供不同的布局

By default, Android resizes your application layout to fit the current device screen. 默认情况下,Android会调整应用程序布局的大小以适合当前设备屏幕。 In most cases, this works fine. 在大多数情况下,这可以正常工作。 In other cases, your UI might not look as good and might need adjustments for different screen sizes. 在其他情况下,您的UI可能看起来不那么好,可能需要针对不同的屏幕尺寸进行调整。 For example, on a larger screen, you might want to adjust the position and size of some elements to take advantage of the additional screen space, or on a smaller screen, you might need to adjust sizes so that everything can fit on the screen. 例如,在较大的屏幕上,您可能需要调整某些元素的位置和大小以利用额外的屏幕空间,或者在较小的屏幕上,可能需要调整大小以使所有内容都适合屏幕。

The configuration qualifiers you can use to provide size-specific resources are small, normal, large, and xlarge. 可用于提供特定于大小的资源的配置限定符为small,normal,large和xlarge。 For example, layouts for an extra large screen should go in layout-xlarge/. 例如,超大屏幕的布局应放在layout-xlarge /中。

Beginning with Android 3.2 (API level 13), the above size groups are deprecated and you should instead use the swdp configuration qualifier to define the smallest available width required by your layout resources. 从Android 3.2(API级别13)开始,不建议使用上述大小组,而应使用swdp配置限定符定义布局资源所需的最小可用宽度。 For example, if your multi-pane tablet layout requires at least 600dp of screen width, you should place it in layout-sw600dp/. 例如,如果您的多窗格平板电脑布局需要至少600dp的屏幕宽度,则应将其放置在layout-sw600dp /中。 Using the new techniques for declaring layout resources is discussed further in the section about Declaring Tablet Layouts for Android 3.2. 关于声明Android 3.2平板电脑布局的部分中,将进一步讨论使用新技术声明布局资源。

There are two approaches to solve this problem. 有两种方法可以解决此问题。

First 第一

define your drawables like below. 如下定义您的可绘制对象。

drawable-small-mdpi
drawable-normal-hdpi
drawable-large-hdpi
drawable-xlarge-hldpi

Ref : Screen Compatability issue in android 参考: Android中的屏幕兼容性问题

Second 第二

If you like to provide density wise drawables, following way you can do this. 如果您想提供密度明智的可绘制对象,请按照以下方式进行操作。

For Example, if you want to set drawable for smallest width of 600 dp then create directory with name 例如,如果您想将drawable设置为最小宽度为600 dp,则创建目录,名称为

drawable-sw600dp

as like for 720 dp, create directory with name 就像720 dp一样,用名称创建目录

drawable-sw720dp

This way you can define density wise drawable directory. 这样,您可以定义密度明智的可绘制目录。

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

相关问题 如何在Android中使图像支持不同的屏幕尺寸或密度? - How to make an image support different screens sizes or densities in Android? Android:如何创建不同大小和密度的图像? - Android : How to create images for different sizes and densities? 如何在Android中支持多个屏幕,而无需为不同的屏幕密度提供不同的位图可绘制对象 - How to Support Multiple Screens in Android without the need to Provide different bitmap drawables for different screen densities android-如何为具有不同密度的不同屏幕尺寸创建avd - android - how to create Avd's for different screen sizes with different densities 如何在Android中支持不同的屏幕 - How to support different screens in android 支持不同android屏幕尺寸和密度的技术 - Techniques in supporting different android screen sizes and densities 如何针对不同的屏幕密度确定字体大小? - How to target font sizes for different screen densities? 如何在 Unity 中为 android 设备支持不同的恶意密度? - How to support different spites densities in Unity for android devices? 适用于不同屏幕的Android文本大小 - Android Text Sizes for different screens 支持不同尺寸和密度的图像 - Supporting different sizes and densities imageview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM