简体   繁体   中英

I am confused with drawable-hdpi and drawable-mdpi

i am attempting to get my android app to work on both phone type devices and tablets. for the layouts i have layout-normal and layout-large and i place my xml files inside each and it seems to select the correct one for each device (layout-normal for phones and layout-large for tablets).

however the problem arises for the drawable folders. i have drawable-hdpi, drawable-mdpi and drawable-ldpi. the tablet is taking its images from the drawable-mdpi, and the phone is taking its images from the drawable-hdpi. from the reading i have been doing this seems to be backwards??? this seems to happen on both the emulator and real devices, could i be doing something wrong? am i mixing something up?

Clayton,

drawable-hdpi and drawable-mdpi is not related to the size of the screen itself, but to the resolution of the display.

It's probably easy to think in terms of the iPhone 3GS and 4 for this (bear with me please). The 4 has retina display, hence a much higher resolution. Using the same sprites you'd use with the 3GS would result in a blurry display.

Android phones are, if anything, much more diverse in terms of screen options.

If you want to be able to aim different layouts at different resolutions, please try putting the layouts into /layout-xlarge, /layout-large, etc...

You can find more here:

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

There are some changes that you can see for Android 3.2 and above:

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. For example, if your multi-pane tablet layout requires at least 600dp of screen width, you should place it in layout-sw600dp/. Using the new techniques for declaring layout resources is discussed further in the section about Declaring Tablet Layouts for Android 3.2.

ldpi,mdpi和hdpi指的是像素密度,而不是屏幕尺寸。

The accepted answer does not address a serious problem: if you have many drawables, you end up with an unnecessarily big apk file because of resource duplicating. The only solution for that is the resource alias option described here: http://blog.evendanan.net/2011/03/Android-resources-and-device-fragmentation

Edit : I just beheld that OP didn't realize that most phones have hdpi density, while most tablets have mdpi density. At the same time the tablets mostly have higher resolution. Hence Android will use smaller pictures for higher resolution. You can overcome this only by using vector images or using the methods described in the accepted answer and in my answer.

drawable-hdpi - 当设备具有高像素密度drawable-mdpi时,应用程序使用此可绘制图像 - 当设备具有中等像素密度drawable-ldpi时,应用程序使用此可绘制图像。应用程序在设备具有低像素密度时使用此可绘制图像

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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