I'm writing an Android app and have read up everything I can find on fragmentation and handling multiple screens, particularly from the official Android documentation.
I understand different screen densities utilize the various folders (mdpi, hdpi etc.) for images of varying sizes, and different screen sizes can utilize different layouts by defining them in res/layout-sw600dp layout-sw720dp etc. which all makes sense.
However, when developing my app my primary test device was a HTC Desire X phone 400x800 with 240dpi density and all looks well. I then tested it on a Prestigio Multipad 8.0 tablet and this is where I'm getting confused. The tablet has a screen size of 786x1232 BUT the screen density is only 160dpi. Owing to the fact that the screen density on the tablet is smaller, Android therefore uses the images in the mdpi folder for the tablet, and the slightly bigger ones in the hdpi folder for the phone! This therefore results in images way too small on the tablet.
I don't need to edit the layout for the tablet so the sw720dpi folders aren't a help.
What am I missing or not understanding properly here? How can I make my images scale up for the bigger, lower density tablet screen?
OK, I figured this out eventually. My mistake was I didn't realize drawables work exactly the same as layouts in that I could have a drawable-sw720dp folder which Android fetches the images from in the case of a screen with at least 720pixels of width. For completeness in the scenario I described I could have a drawable-sw720dp-mdpi folder in which to store my images.
I had an additional issue then whereby I had 2 copies of the same image in different drawable folders but I discovered you can reference images using an alias just like layouts. Details of how to do that can be found here.
Related
I'm having trouble getting my application to be scalable to different screen sizes on release.
I read through the support documentation at developer.android.com, Supporting Multiple Screens.
At first the app was just using one size version of images that looked fine on my sony xperia (note. with all height & width set to 'wrap_content'). however when I started trying out the emulated devices (ldpi, hdpi & xhdpi) the sizing was not relating to the display.
Below Are Two examples, the first being the correct view. the size & positioning is as expected
The latter is viewed at xhdpi, or the highest resolution that SDK emulator offers.
the positioning is correct, however the sizing is wrong. (sorry about the screenshot size)
I took to my editor & created the images again, one for each display type (mdpi, hdpi, xhdpi) & inserted into the relating resource folders.
I ran the test again, but still had the same sizing issue.
I'm not 100% with this part of android & would appreciate any help or pointers to resolving this issue
p.s please excuse the blanked out sections, they are in place to protect identity.
I don't see anything wrong with the screenshots, a screen with extra high density probably has a very big size (in pixels) so images take a smaller part of the screen. The solution to your problem is to make bigger images for screens with bigger size. From google's Supporting Multiple Screens that you've read you can create a folder like drawable-normal-mdpi for screens with normal size, or drawable-xlarge-mdpi etc etc
It's not an uncommon problem, just make bigger images for bigger screens, I had this issue when dealing with tablets, there was so much empty space because the screen is so much bigger.
I am developing app for Mobiles(HTC) and Motorola Xoom. But the problem i am facing is that both Uses Drawable-mpdi bitmaps.
abd there is difference in screen size of both, The Image which is perfect on Mobile is became very small on Tablet.
I have checked the list for Drawable folders used by devices.
Please Help me how to sort out this Problem ?
How can I make different size images for both of devices.
Thanks
I can think of a couple of ways to do this. Hopefully, other people will add more.
You could use the MDPI folder with a single image of high enough resolution for the tablet then let Android scale it for smaller devices using the scale properties of an ImageView. However, you are focusing only on HTC and Xoom and that doesn't solve your problem for devices which use other generic resolutions.
Or, you could use the drawable-nodpi folder and have several images with your own resolution naming scheme e.g. myimagesmall.bmp, myimagemedium.bmp etc. Then at runtime, measure the device screen size and DPI and load the appropriate image.
Or, combine them. Use nodpi and a single image and let Android scale for you. Using BitmapFactory, you can control dithering and anti-aliasing to get good results.
Good luck!
Speaking about density, Motorola XOOM also uses mdpi drawables, so to differenciate drawables between tablets and small phones you should use folders with respect to screen sizes. Phone screen size is usually treated as normal, and a 10-inch tablet is xlarge, so drawable-xlarge-mdpi is the folder name you should use to place drawables for 10-inch tablets. Hope this helps.
From the http://developer.android.com/guide/practices/screens_support.html
The configuration qualifiers you can use to provide size-specific resources are small, normal, large, and xlarge. For example, layouts for an extra large screen should go in 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. 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
What simulator resolution i should keep when developing application for Samsung galaxy s2 and galaxy s3 ?
What i found that samsung galaxy s2 has 480x800 resolution and s3 has 1280x720 resolution so what i have understood up till now that I should ask my graphics designer to provide me hdpi graphics that contain 480x800 background images and to implement same background image in galaxy s3 mobile, I will use image of size 1280x720 and put in xhdpi folder so that it can work on s3.
The background image is something which covers whole available area for mobile app. so am i right ??
You will need to create several emulators or get various devices.
There are some pretty important ones, so generally you need to make sure you have:
ldpi, mdpi, hdpi, xhdpi
and
small, medium, large, xlarge
Some people choose to exclude certain sizes (like small and ldpi) but htat's up to you,
if you go with some or all of the following, it should be a good start:
480x320 (SE Mini 10), 480x800 (GS2, Desire, etc), 1280x720 (GS3, Galaxy Nexus etc), 1280x800 (Note, Xoom, various other tablets)
HTC ChaCha (because it's landscape default)
You need to make sure you create resources in the relevant folders for each density, usually, I tend to ignore ldpi and just put resources in:
mdpi,hdpi and xhdpi (mdpi will be scaled down for ldpi devices,
automatically)
You may also need to create various portrait and landscape layouts in different sizes.
Reading this page provides most of the necessary information:
http://developer.android.com/guide/practices/screens_support.html
This page also contains important information regarding size distribution and popularity that is constantly up to date:
Android Stats
One thing that Android does for you is that it manages resolution. If you use the proper size formats (dp, sp, etc), your layout will scale to almost all resolutions. If you place images in the proper drawable folders (hdpi, ldpi, mdpi, etc), the OS will also swap those out as necessary.
Also, the emulator should handle resolutions for specific devices, if I recall correctly.
Desing lazout in smart way! Usualy it means don't put to mutch content in one layout.
Make sure that evrything looks good on smallest size and bigest size. It is better to treat tablets separetly. Read how providing alternative resources works, you can build sepereate layouts for each screen size.
Check if the hardware is available on that device before using it. hasSystemFeature() can be used for checking.
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, and hdpi refer to pixel density, not screen size.
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 - application use this drawable images when the device has high pixel density
drawable-mdpi - application use this drawable images when the device has medium pixel density
drawable-ldpi.-application use this drawable images when the device has low pixel density
As per managing resources(images) in > Android 1.6 version, we need to keep different-resolutions image in Drawable-Hdpi, Drawable-Mdpi, Drawable-Lpi folder particularly.
And as per this page: http://developer.android.com/guide/practices/screens_support.html ,
In Low density section - there are three resolutions used: 240*320 , 240x400 , 240x432 for the Small screen, Normal Screen, Large Screen particularly.
same way for Medium density section - there are three resolutions used: 320x480 , 480x800 , 480x854 for the Small screen, Normal Screen, Large Screen particularly.
and same way for High density ........
but i am confused here:
(1) How do i come to know that whether small, Normal or Large screen is used, i mean is there any way to know ?
(2) How do i come to know which type of density i am using ?
(3) And in Drawable-Hdpi, Drawable-Mdpi, Drawable-ldpi folder, which resolution's image we should keep particularly?
There are specific Android API calls that can, at runtime tell you what density and (small/large/normal) screen size a handset has. However, as a developer we should not need to worry about individual handsets at all. All we need to do is to have ldpi/mdpi/hdpi assets and small/normal/large layouts in the apk. Android internally handles everything.
Dont forget to get an indepth understanding of how Android determines which assets to use and aliasing here.
Why do you want to know the actual density? It's Android's business. But I'm sure there is a way to retrieve this information.
For development I put everything in the hdpi-folder. I also could put everything in a general Drawable Folder.
At the time u publish u can decide if u want to provide already downscaled resources for ldpi and mdpi. However, thats not necessary.
Update: Retrieve actual density with this class and best practices
Update 2: I found a 25 min video from Motorola discussing all those issues: Working with multiple screens
1) Change the content of the layout in different folders i.e layout-small, layout-large, etc Now test it in Different emulator with different screen resolution.
2) For Finding out density of the Device use
Log.d("Density", "" + (getResources().getDisplayMetrics().density));