I am following this tutorial link
There three types of screens
xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp
But there are three folders
drawabale-hdpi
drawabale-mdpi
drawabale-ldpi
I placed images of xlarge in hdpi
that of large in mdpi
and that of normal in ldpi
but where to place the images of small screens?
Sorry for bad english
For example, The following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for small, medium, high, and extra high density screens.
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
and Screen Sizes.
I hope this help.
hdpi, mdpi and ldpi refer to the screen density in dots-per-inch. This is completely separate from the screen size (small, large, etc).
You can have large screen with low density, or a small screen with high density, etc.
You can cater for different screen sizes by putting different layout resources in res/layout-small, res/layout-large, etc.
These are two different things - hdpi/mdpi/ldpi are screen densities (i.e., how many pixels per square centimeter) while xlarge/large/normal/small are screen sizes (the physical dimensions of the screen). So the small screen images would go in drawable-small, normal in drawable-normal, etc.
There's a lot more info about this stuff on the Android developer website.
Screen size has no relation with density. xlarge screen does not mean it has hdpi density. For example tab like galaxy 10.1 pr motorola xoom has xlarge screen but mdpi density so for them you make a separate folder drawable-xlarge. and for this you have to add android:xlargeScreens="true" in manifest.
And devices like galaxy s2 or htc desire has hdpi density. Devices with small screens like galaxy pop are mostly have ldpi density, normal screens like galaxy ace are mostly mdpi devices and devices with large screens like galaxy s2 are mostly hdpi devices, and some devices like tab P1000 have large screens but mdpi density and for them you have to make folder drawable-large-mdpi.
Related
I'm a little confused about how to determine which phones support what layout types. I've done some research but haven't found a satisfying answer.
For example, I've found the below guide:
xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp
However, I still have some concerns:
Samsung grand (480*800) and HTC wild fire S (320*480) both support MDPI. These screens have very different resolutions, yet have the same layout type?
Galaxy note 2 (1280*720) support HDPI. If HD (720p) is only HDPI, when what device/resolution supports XHDPI?
I've already asked a related question here: How to set layout on 7" two different tablet?.
My most important question, however, is this: How do I know which devices or screen resolutions support each layout type?
Android treats mdpi (160 pixels/inch) as the base density. So for mdpi devices, 1 dp = 1 pixel. At higher densities, there are more pixels per inch (240 for hdpi, 320 for xhdpi).
AutoMatic Scaling by Android itself:
Android attempts to make graphic images occupy the same physical dimensions on the screen regardless of the device pixel density. So if all it finds is an mdpi resource, and the device is hdpi, it will scale the graphic by 240/160 = 150%, and it will double the size of the graphic for xhdpi.
Using different versions of graphics :
If you don't want this automatic scaling (which can make graphics look poor), you can simply supply your own version of graphic resources for use at higher densities. These graphics should be of the same size that Android would scale an mdpi resource.
Note : the pixels/inch that was stored in the image file has nothing to do with this. It's all based on where you put the graphics files in the resources directory for your project. Any graphics placed in res/drawable are assumed to be properly sized for mdpi displays, as are graphics placed in res/drawable-mdpi. Image files that it finds in res/drawable-hdpi are assumed to be properly sized for hdpi displays, etc. When your program runs on a particular device, Android will first look for a graphic that matches the display density of that device. If it does not find one but instead finds one for a different density, it will use that and automatically scale the image based on the above rules.
As the ldpi, mdpi and hdpi refer to screen density, which means how much pixels can fit into a single inch.
the ratio in pixels between them is:
ldpi = 1:0.75
mdpi = 1:1
hdpi = 1:1.5
xhdpi = 1:2
xxhdpi = 1:3
so lets take an image with about the size of 100X100:
for mdpi it should be 100X100
for ldpi it should be 75X75
for hdpi it should be 150X150
for xhdpi it should be 200X200
for xxhdpi it should be 300X300
this way, for screens with the same size but different DPI, all the images seem the same size on screen.
look into these details: android manages all this by itself, you just have to provide layouts and images in relative folders
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
I have created a layout in my xml file and have a LinearLayout that is displayed at the top of the activity. I have set its width to fill_parent and its height to 54dp. The height of the layout looks good on devices with bigger screens like Samsung Galaxy, but on smaller devices it looks too big. Is there anyway that the layout will have different height on different screen sizes? I am guessing that this might be achieved by dp, dip, etc. but I'm not sure as to what exactly they do
make layout-normal-hdpi, layout-normal-mdpi and layout-normal-xhdpi folders and copy the same xml in all the three folders than set the different height on each xml as per the devices. This is the standard technique which is been followed. Try this you will surely get desired result.
Hope this will help you...
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
Low density Small screens QVGA 240x320
res/layout-small-ldpi
res/layout-small-land-ldpi
Low density Normal screens WVGA400 240x400 (x432)
res/layout-ldpi
res/layout-land-ldpi
Medium density Normal screens HVGA 320x480
res/layout-mdpi
res/layout-land-mdpi
Medium density Large screens HVGA 320x480
res/layout-large-mdpi
res/layout-large-land-mdpi
High density Normal screens WVGA800 480x800 (x854)
res/layout-hdpi
res/layout-land-hdpi
Xoom (medium density large but 1280x800 res)
res/layout-xlarge
res/layout-xlarge-land
Comment me for any query...
i am working on 2.2 version of android and xml is designed according to this version
Specification of emulator : version 2.2, Built-in : HVGA , Memory : 1024
and now i need this application to be transformed into 4.0 version of Samsung galaxy s3 but the screen are very streched and does not look good
thanks in advance if any help.
You have to create multiple resources for your app. Android has 4 resolutions (ldpi,mdpi,hdpi and xhdpi) and 4 generalized screen sizes (small, medium, large and extra large). So you have to make 4 layouts (or 3 if you don't plan on supporting tablets, since tablets come under the extra large category) to support the screen sizes.
Here's a general guide:
put layouts for small, medium, large and extra large in your res/ folder as follows:
res/layout/sample_layout.xml // default layout
res/layout-small/sample_layout.xml // layout for small screen size
res/layout-large/sample_layout.xml // layout for large screen size
res/layout-xlarge/sample_layout.xml // layout for extra large screen size
you can also use
res/layout-land/sample_layout.xml for landscape orientation for all screen sizes or you can target landscape layouts for specific screen sizes as res/layout-medium-land/sample_layout.xml
note that all the layouts have the same name.
once you have your layouts ready, you need to take care of image resolutions also
once again in your res/ folder add images like this:
res/drawable-ldpi/sample_image.png // low density
res/drawable-mdpi/sample_image.png // medium density
res/drawable-hdpi/sample_image.png // high density
res/drawable-xhdpi/sample_image.png // extra high density
once again, all the images have the same name.
general guidelines for designing images are:
ldpi is 0.75x dimensions of mdpi
hdpi is 1.5x dimensions of mdpi
xhdpi is 2x dimensinons of mdpi
generally, I design mdpi images for a 320x480 screen and then multiply the dimensions as per the above rules to get images for other resolutions.
Android will automatically select the best combination of layout and image depending on the device. For example, for a high resolution medium size device, layout-medium and high density image will be displayed to the user.
Make sure you create emulators for all these combinations and test your app thoroughly. here's the official docs for more info:
https://developer.android.com/guide/practices/screens_support.html
You have to maintain your xml files in
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
Check this Supporting Multiple Screens for how to design your layout for supporting multiple screens
and also for images use
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
Thais is what I have done. I try to support this screen sizes:
xlarge screens 640dp x 960dp
large screens 480dp x 800dp
normal screens 320dp x 400dp
small screens 240dp x 400dp
So I create etc. background images with that sizes (640dp x 960dp, 480dp x 800dp, 320dp x 400dp and 240 x 400). I put images in folders drawabale-xhdpi, drawabale-hdpi, drawabale-mdpi and drawabale-ldpi.
When I have xlarge screen with hdpi density (it use images from hdpi folder), graphic is bad (images are not large enough). So how to use that xlarge image when I have hdpi density. Do I have to create more images and put them in some places? This is a game, I draw all in canvas, don't use layouts for drawing images.
Thanks.
You can add new drawables in a drawable-xlarge-hdpi folder
use this path to save your image
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
Check this Supporting Multiple Screens for more clarifications of multiple screen support.
Take a look at this link - Providing Resources
You can have an image in drawable-xlarge-hdpi folder
always use relative layouts to support multiple screens. see here Android layouts for same density different diagonal length
My app has 2 different resolution support, 480x800 and 320x240, i have created folder for them for instance layout-normal-hdpi and layout-normal-mdpi. But somehow emulotor is not picking up the ui for hdpi. I have created different layout aswell.
the way i am dealing with multiple screen is this way and its working fine.....if any one has improved wayso do guide me
Screen size 480x800
layout-normal-hdpi-480x800
drawable-normal-hdpi-480x800
Screen size Galaxy Nexus---
though its size is 1280x720 but in actual due to system bar its dimension(screen size) differs
layout-normal-xhdpi
drawable-normal-xhdpi
Screen size Note 5.3---
layout-normal-xhdpi-1280x800
drawable-normal-xhdpi-1280x800
Screen size S3---
layout-normal-xhdpi-1280x720
drawable-normal-xhdpi-1280x720
Screen size 7inch tab 2 supporting OS version 3 and above---
dont write dimension 1026x600 bsz in actual due to system bar its dimension(screen size) differs
layout-large-mdpi
drawable-large-mdpi
Screen size 7inch tab p1000 etc supoorting os verion less than 3---
layout-large-hdpi-1024x600
drawable-large-hdpi-1024x600
Screen size 1280x800 tab 10.1,10.2,note 10.1 etc---
you can add dimension if you want other wise it is fine
layout-xlarge-mdpi
drawable-xlarge-mdpi
From the documentation:
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
layout-normal-mdpi does not exist. Use layout-mdpi instead.
For reference: http://developer.android.com/guide/practices/screens_support.html
The Api level must also support this: Android - layout-large folder is been ignored
Handling different resolutions can get tricky on Android.
The one true resource for this is the official site:
http://developer.android.com/guide/practices/screens_support.html
It sounds to me like you might be confusing the size with the pixel intensity here.
Try to create the folders:
res/layout-sw480dp/main_activity.xml //for the large screen
and
res/layout-sw320dp/main_activity.xml //for the small one
Do you also have different drawable resource folders? Did you manage to get them to work?
Android Support Multiple Screeen
for tablet
Resolution 1280x800/1280x720
values-sw720dp
drawable-sw720dp
layout-sw720dp
Resolution 1024x600
values-sw600dp
drawable-sw600dp
layout-sw600dp
Resolution 480x800(twinner resolution, mdpi in tablet & hdpi in mobile)
values-large-mdpi
drawable-large-mdpi
layout-large-mdpi(incase you want to make separate layout)
for moblie
Resolution 1080x1920
values-sw360dp-xxhdpi/values-sw360dp-notlong-xxhdpi (when 768x1280 is used)
drawable-xxhdpi/drawable-sw360dp-xxhdpi/drawable-sw360dp-notlong-xxhdpi(when 768x1280 is used)
layout-sw360dp
Resolution 720x1280
values-sw360dp-xhdpi
drawable-sw360dp-xhdpi
layout-sw360dp
Resolution 768x1280
values-sw360dp-notlong-xhdpi
drawable-sw360dp-notlong-xhdpi
layout-sw360dp
Resolution 540x960
values-sw360dp-hdpi
drawable-sw360dp-hdpi
layout-sw360dp
Resolution 480x800
values-hdpi
drawable-hdpi
layout-hdpi
Resolution 320x480
values-mdpi
drawable-mdpi
layout-mdpi
Resolution 240x320
values-ldpi
drawable-ldpi
layout-ldpi
tags to add in manifest if your app needs to support full hd device only
for 1080x1920
<screen
android:screenDensity="480"
android:screenSize="normal" />
Courtesy: (Maulik Joshi)