简体   繁体   English

适用于Values文件夹的Android hdpi / mdpi / ldpi?

[英]Android hdpi/mdpi/ldpi for Values folder?

Android allows us to define hdpi/mdpi/ldpi for the drawable folder in order to account for different sized screens/devices. Android允许我们为drawable文件夹定义hdpi / mdpi / ldpi,以便考虑不同大小的屏幕/设备。 I was wondering if that same support can be applied for the Values folder (or even the layout folder)? 我想知道是否可以为Values文件夹(甚至布局文件夹)应用相同的支持? Reason being, I typically define a "sizes.xml" file which holds standard dp sizes that I apply to margins and paddings. 原因是,我通常定义一个“sizes.xml”文件,其中包含我应用于边距和填充的标准dp大小。 I also do the same for sp sizes for text. 我也对文本的sp大小做同样的事情。 I'd like to adjust those values based on the phones dpi. 我想根据手机dpi来调整这些值。

Yes, you can. 是的你可以。 Just like this: 像这样:

res/values/dimens.xml(default)
res/values-ldpi/dimens.xml   (240x320 and nearer resolution)
res/values-mdpi/dimens.xml   (320x480 and nearer resolution)
res/values-hdpi/dimens.xml   (480x800, 540x960 and nearer resolution)
res/values-xhdpi/dimens.xml  (720x1280 - Samsung S3, Micromax Canvas HD, etc) 
res/values-xxhdpi/dimens.xml (1080x1920 - Samsung S4, HTC one, etc)
res/values-large/dimens.xml  (480x800)

res/values-large-mdpi/dimens.xml (600x1024)
res/values-sw600dp/dimens.xml  (600x1024)
res/values-sw720dp/dimens.xml  (800x1280)
res/values-xlarge-xhdpi/dimens.xml (2560x1600 - Nexus 10")
res/values-large-xhdpi/dimens.xml  (1200x1920 - Nexus 7"(latest))

(from: http://wiki.jikexueyuan.com/project/android-actual-combat-skills/multi-resolution-adapting-common-directory.html Warning: the link is chinese!!! To translate, right click on the page, click "translate to English" in the popup menu.) (来自: http//wiki.jikexueyuan.com/project/android-actual-combat-skills/multi-resolution-adapting-common-directory.html警告:链接是中文!!!要翻译,请右键单击页面,在弹出菜单中单击“翻译为英语”。)

Yes, I believe anything in the res/ folder can use "Configuration Qualifiers". 是的,我相信res/文件夹中的任何内容都可以使用“配置限定符”。 So for example, you can have a values-sw600dp-mdpi-land/ folder. 例如,您可以拥有values-sw600dp-mdpi-land/文件夹。

See "Using Configuration Qualifiers": http://developer.android.com/guide/practices/screens_support.html#qualifiers 请参阅“使用配置限定符”: http//developer.android.com/guide/practices/screens_support.html#qualifiers

I first noticed this by looking at Google's IOSched app sample code, look at the res folder: https://github.com/google/iosched/tree/master/android/src/main/res 我首先通过查看Google的IOSched应​​用示例代码注意到这一点,查看res文件夹: https//github.com/google/iosched/tree/master/android/src/main/res

You'll see that they have "values-sw600dp-land", "values-w400dp" and "values-v17" folders, just to name a few. 你会看到他们有“values-sw600dp-land”,“values-w400dp”和“values-v17”文件夹,仅举几例。

As values folders are more suitable to use for setting different margins and font sizes based on device resolution, though some hdpi devices takes values from values-xhdpi. 由于某些hdpi设备从values-xhdpi获取值,因此值文件夹更适合用于根据设备分辨率设置不同的边距和字体大小。 So instead using values-normal-hdpi, values-normal-xhdpi is more appropriate answer. 因此,使用values-normal-hdpi,values-normal-xhdpi是更合适的答案。

By using this, we can also omit need of different layout folders by setting different dps and sizes in values folders to support phones and tablets very easily. 通过使用它,我们还可以通过在值文件夹中设置不同的dps和大小来省略不同布局文件夹的需要,以便非常轻松地支持手机和平板电脑。

Yes, you can define files to be used based on whatever the standard modifiers are. 是的,您可以根据标准修饰符定义要使用的文件。 For instance, in one of my apps I have defined styles.xml and strings.xml files for various sizes and orientations and it all works as expected values-large-hdpi and values-large-land-hdpi, etc. 例如,在我的一个应用程序中,我为各种大小和方向定义了styles.xml和strings.xml文件,它们都可以作为预期值 - large-hdpi和values-large-land-hdpi等。

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

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