设置可绘制文件夹以用于不同的分辨率 [英] Setting drawable folder to use for different resolutions
问题描述
我的应用中需要使用的每个图标都有 4 种不同的尺寸.问题是我的 Nexus 7 (1280 x 800) 和 Galaxy s2 (800 x 480) 似乎使用了 drawable-hdpi 中的资源.如何强制 Nexus 使用 drawable-xhdpi 中的资源,然后 10 英寸选项卡使用 drawable-xxhdpi.
I have 4 different sizes for each of the icons I need to use in my app. The problem is My Nexus 7 (1280 x 800) and galaxy s2 (800 x 480) seem to use the resources in drawable-hdpi. How do I force the Nexus to use resources in drawable-xhdpi and then the 10 inch tab to use drawable-xxhdpi.
我的清单文件中有这个
<supports-screens android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
推荐答案
如何强制 Nexus 使用 drawable-xhdpi 中的资源,然后使用 drawable-xxhdpi 的 10 英寸标签?
How do I force the Nexus to use resources in drawable-xhdpi and then the 10 inch tab to use drawable-xxhdpi?
你不能.
限定符hdpi,xhdpi,xxhdpi
描述了设备的屏幕密度,而不是屏幕的大小.来自官方文档
The qualifiers hdpi,xhdpi,xxhdpi
describes the screen density of the device, not the size of screen.
From the official doc
屏幕密度
屏幕物理区域内的像素数量;通常称为 dpi(每英寸点数).例如,低"密度屏幕在给定物理区域内的像素较少,相比之下正常"或高"密度屏幕.为简单起见,Android 将所有实际屏幕密度分为四种广义密度:低、中、高,而且特别高.
The quantity of pixels within a physical area of the screen; usually referred to as dpi (dots per inch). For example, a "low" density screen has fewer pixels within a given physical area, compared to a "normal" or "high" density screen. For simplicity, Android groups all actual screen densities into four generalized densities: low, medium, high, and extra high.
如果您还想支持平板电脑,请使用 large, xlarge
限定符.Nexus 7 是 large-hdpi
平板电脑(技术上它是 tvdpi
,但从 hdpi
获取图像).因此,如果您想为 Nexus 7 放置图像,请创建一个名为 drawable-large-hdpi
的文件夹并将图像放在那里.
If you want to support tablets also, use large, xlarge
qualifiers. Nexus 7 is a large-hdpi
tablet(technically it's tvdpi
, but takes images from hdpi
). So if you want to put images for Nexus 7, make a folder named drawable-large-hdpi
and put the images there.
注意:这是 Nexus 7 的特例.因为即使 Nexus 7 是 7 英寸平板电脑,它也具有 1280 * 800 的分辨率.所以它是一个 hdpi
设备.但普通 7 英寸设备的分辨率较低,为 1024 * 600.所以它们是 mdpi
设备.所以 drawable 限定符可以改变.(根据我自己的经验,先放一个7寸设备的文件夹drawable-large-mdpi
,然后在Nexus 7上查看.如果图片没有问题,就不用再放一个文件夹了.因为如果特定文件夹不存在,Android 将检查最近的可能文件夹并针对设备屏幕对其进行优化)
Note: This is the special case for Nexus 7. Because even though Nexus 7 is a 7 inch tablet, it has resolution of 1280 * 800. So it's an hdpi
device. But normal 7 inch devices have lower resolutions of 1024 * 600. So they are mdpi
devices. So the drawable qualifier can change. (From my own experience, first put a folder drawable-large-mdpi
for 7 inch devices and check it on Nexus 7. If there is no problem with images, you dont have to put another folder. Because if a particular folder is not present, Android will check for the nearest possible folder and optimize it for the device screen)
现在关于 10 英寸平板电脑外壳,它们是 xlarge
设备,它们的密度可以从 mdpi
更改为 xhdpi
(Nexus 10).但许多具有 1280 * 800 的分辨率,并且它们是 mdpi
设备.
Now regarding the 10 inch tablets case, they are xlarge
devices and their densities can change from mdpi
to xhdpi
(Nexus 10). But many have resolution of 1280 * 800 and they are mdpi
devices.
更好的做法是放以下drawables
The better practice is to put the following drawables
// for Phones
drawable-ldpi
drawable-mdpi
drawable-hdpi
//for 7 inch tablets
drawable-large-mdpi
drawable-large-hdpi(for Nexus 7)
// for 10 inch tablets
drawable-xlarge-mdpi
这篇关于设置可绘制文件夹以用于不同的分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!