我对每一个我需要在我的应用程序使用的图标4种不同的尺寸。 问题是我的Nexus 7(1280×800)和Galaxy S2(800×480)似乎绘制,华电国际利用的资源。 如何强制的Nexus绘制-xhdpi,然后将10英寸的标签使用可绘制-xxhdpi利用资源。
我有这个在我的清单文件
<supports-screens android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
How do I force the Nexus to use resources in drawable-xhdpi and then
the 10 inch tab to use drawable-xxhdpi?
You can't.
The qualifiers hdpi,xhdpi,xxhdpi
describes the screen density of the device, not the size of screen.
From the official doc
Screen density
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.
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.
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)
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.
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
尝试使用Configuration qualifiers
为你的资源。 这是最好的做法。 像res/drawable-normal-hdpi-port/icon.png
。
参考链接: 配置预选赛
谢谢。
The problem is My Nexus 7 (1280 x 800) and galaxy s2 (800 x 480) seem to use the resources in drawable-hdpi
这取决于设备一样nexus 7
具有240dpi
这是hdpi
设备将需要绘制资源从华电国际这样的,如果你测试在同samsung
tab 2
,将采取相同的绘制从mdpi
,因为它是一个MDPI设备