Android multi Screen Support - android

I know that for supporting different screen size we use layout,layout-large,layout-xlarge folder , but i have confusion regarding drawable folder,by default they are ,
1. drawable-ldpi For low density screens
2. drawable-mdpi For medium density screens
3. drawable-hdpi For high resolution screens
4. drawable-xhdpi For extra high resolution screens
But A simple approch is
1.Drawable
2.Drawable-large
3.Drawable-xlarge
is it ok to go with this approch?

Google changed layout system after API 13 (Android 3) so both of them works but it's recommended to use dpi system which related to screen density but old system was realted to screen sizes which might make problems with large screen devices with low dpi screen density

It is better to use screen density folders because (quoting the Android doc)
Maintaining density independence is important because, without it, a UI element
(such as a button) appears physically larger on a low density screen and smaller
on a high density screen. Such density-related size changes can cause problems in
your application layout and usability.
So using density-pixels Android scales your widgets (Buttons, ImageViews, etc) by itself relating your Activity and the Drawables you need to the appropiate res folder. In fact, you should be using this density system in your Layouts too (layout-mdpi, layout-hdpi, etc).

Related

Problems in supporting multiple resolutions

I am having trouble managing my application layouts in three different resolutions; 720x1280, 1080x1920 and 1440x2560.
In drawable-xhdpi folder is the corresponding images to 720x1280 resolution.
The folder drawable-xxhdpi is the corresponding images to 1080x1920 resolution and in drawable-xxxhdpi to 1440x2560.
I began to adjust the screens in layout folders. The layout-sw360dp was setting screens for 720x1280 and the layout-sw480dp the 1080x1920.
When testing in the emulator 720x1280 all settings worked perfectly.
But to test the emulator 1080x1920, oddly taking this information in layout-sw360dp folder and not the layout-sw480dp.
In the case of adjusting each folder layout-sw360dp and layout-sw480dp, I'm using margin with values ​​in 'dp' and emulator higher values ​​(layout-sw480dp) are being dropped are being used and the values ​​of the layout-sw360dp.
How can I manage three screen sizes correctly?
Well designed Android applications cater for varying screen sizes, the screen size being a function of both resolution and density. Using several layout-sw###dp folders allows you to vary the layout according to the width of the display, e.g. showing fewer elements and controls on a small screen and perhaps more detail on a large one.
The 'sw' in the layout folder name is the 'shortest width' a display must have in device independent pixels (dip). One dip = 1 real pixel on a 160 density screen. So on a 320 density screen, 2 real pixels make up one dip.
Your nexus 5 has 480/160 = 3 real pixels per dip. So with a width resolution of 1080, that is 360dip wide.
Your nexus 4 has 320/160 = 2 real pixels per dip. So with a width resolution of 768, that is 384dip wide.
Neither device is more than 480 dip wide so both use the sw360dp folder.
Both devices are physically very similar in size. The Nexus 5 (5.4inch screen) has more pixels than the Nexus 4 (4.7inch screen) but the pixels are physically smaller. So it is correct that the same layout is used for both. The UI should look the same on both devices, assuming you correctly specify the size and layout of your various UI elements in dip.
As a further example, I have an old tablet (10inch screen) with a resolution of 800x1280 and a low density of 149, hence is 859dip wide. You can comfortably display far more info on a screen that size than on a Nexus 4/5, hence you might consider creating a layout-sw720dp for that.
So you appear to be doing exactly the right thing already by designing different layouts for different screen sizes. Just remember that resolution is not the same thing as screen size. Screen size is a combination of resolution and density.
As for your drawables, you are also already doing the right thing by using drawable-xhdpi, drawable-xxhdpi etc with appropriate resolution images in each one. So for example a small device with an extremely high density would likely use the 1440x2560 images and the sw360dp layout. My low res tablet would use the 720x1280 images, unless you'd put something in drawable-mdpi which is where it would look first.
So firstly you'd create appropriate resolution images in the drawable folders so that they would look as good as possible on different resolution screens. Then create appropriate swxxxdp for your layouts so they take up the appropriate space depending on the physical screen size, i.e. make good use of available screen space on large devices and don't clutter up small ones. It's likely you would want to go further and create -land and -port versions of each as well.
It is worth noting that even if you only have one layout folder and one drawable folder, your application will still work on all devices. Android simply looks for the best choice and if there is only one, it'll use that. Adding in the various folders simply allows you to make your app look as good as possible on a range of devices.
Everything I have discussed here and more is explained in detail at http://developer.android.com/guide/practices/screens_support.html.

Is it correct way to create separate layout file for supporting different screens? [duplicate]

I'm really feeling confused. From the docs at developer.android.com, it seems in order to keep my images scaled correctly (aspect ratio too) across all current Android devices I need all these layouts below. Is that really what everyone is doing? Am I missing something, or should I be going about this a different way?
Low density Small screens QVGA 240x320
------------------------------------------------
layout-small-ldpi
layout-small-land-ldpi
Low density Normal screens WVGA400 240x400 (x432)
------------------------------------------------
layout-ldpi
layout-land-ldpi
Medium density Normal screens HVGA 320x480
------------------------------------------------
layout-mdpi
layout-land-mdpi
Medium density Large screens HVGA 320x480
------------------------------------------------
layout-large-mdpi
layout-large-land-mdpi
High density Normal screens WVGA800 480x800 (x854)
------------------------------------------------
layout-hdpi
layout-land-hdpi
Xoom (medium density large but 1280x800 res)
------------------------------------------------
layout-xlarge
layout-xlarge-land
Your app will work on 100% of the devices with the classic layout.
You can just add some buttons or change the layout in landscape mode by adding some qualifiers but that's up to you!
For instance, on LDPI (small resolution) device, you may want to adjust some buttons or change a little bit to fit the small screen.
You may also want to put some buttons on the right in landscape mode and in the bottom of your layout in portrait!
You do not "have to" use them.
According to Android Dev Protip from Roman Nurik about screen size qualifiers:
If you have custom layouts for larger screen devices such as tablets,
now's the time to stop using the -large or -xlarge resource qualifier
and switch to using -swXXdp or -wXXdp qualifiers. The latter were
introduced in API level 13, which basically all tablets now have
support for according to the latest platform version charts1.
means that for basically all cases where -large would have any effect,
-swXXdp can be used instead to provide more granularity.
So which actual sw or w qualifiers should you use? Here's a quick
just-give-me-something starting point:
7" tablets: Instead of layout-large, use layout-sw600dp.
Example: Nexus 7 = 960×600 dp; the smaller of the two dimensions is
600.
10" tablets: Instead of layout-xlarge, use layout-sw720dp.
Example: Nexus 10 = 1280×800 dp; the smaller of the two dimensions is
800. Some 10" tablets are a bit more narrow so 720 is a commonly used switching point.
There's more to it than just that (you really want to choose switching
points based on your content's minimum requirements, not on device
form factor), but that's a #Protip for another day (::cough:: +Nick
Butcher ::cough::).
In the layout if you do not use AbsoluteLayout, you application is going to be resized to fit the screen.
But in some cases, for smaller screens you need declare a new layout with less components for example.
For images:
You has some options.
Simple ignore some resolutions and let the device choose the best image to it.
Declare on AndroidManifest for wich sizes you want to support.
Or has just one and let the resize screw your application.
Yes. You should define different layout for different screen resolution.
When you are supposed to work with tablet kind of application. That time really you feel that. There is a need of different layout. Because Tablets always comes in different size.
One more thing, When you are working on android, means you should always taste your app with real device. And also test with different size emulators.

Background images for different screens

In my application I have a background for activity. This is an image, I am going to use fitXY for it. I am ok if it will be resized a little (keeping aspect ration is not very important) but not very much.
I am going to prepare few images with different size and for both Portrait and Landscape orientation. I am going to cover about 90% of devices.
My question is the following:
What images sizes I need for background?
What folders under "res" I should put these images?
I would like to get very specific file sizes and folder name where to put these files.
The solution should work on tablets as well.
I just used two images with maximum sizes (one portrait and one landscape). Then android resized the to smaller and it looks quite good for me.
I have one background with resolution: 800*1200 px in drawable folder
and another with resolution: 1200*800 px in drawable-land folder
This works pretty fine on tablets.
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
m/h/xh dpi are the most important. Combine that with the (most common) resolutions and you should be fine for your "90%" target.

Supporting Multiple resolution devices Android

I am stuck in a situation.
I created an application for Samsung Galaxy Tab 7". The same application when i run on the HTC Flyer it shows very small fonts.
I tried following :
I thought may be the screen of HTC Flyer is xhdmi so i crated folders accordingly
res -> values-large-xhdmi -> styles.xml -> <item textsize>20</item>
res -> values-large-> styles.xml -> <item textsize>16</item>
this is not working.. :(
any help will be highly appreciable in this regard.
Thanks.
Check out this recent blog post on sizes: http://android-developers.blogspot.com/2011/07/new-tools-for-managing-screen-sizes.html
A typical 7” tablet has a 1024x600 mdpi screen. This also counts as a
large screen.
The original Samsung Galaxy Tab is an interesting case. Physically it
is a 1024x600 7” screen and thus classified as “large”. However the
device configures its screen as hdpi, which means after applying the
appropriate ⅔ scaling factor the actual space on the screen is 682dp x
400dp. This actually moves it out of the “large” bucket and into a
“normal” screen size. The Tab actually reports that it is “large”;
this was a mistake in the framework’s computation of the size for that
device that we made. Today no devices should ship like this.
So you need to think of the Galaxy as a large sized screen but with hdpi.
THe HTC Flyer will be large sized screen but with mdpi.
When specifying sizes you need to stick with dp, as this normalizes all sizes to scale appropriately for the different density screens. Use a dimension to specify in a xml value resource.
As milind hinted (i think), it is probably better to use the same style for these two screen sizes and specify a dimen resource. This resource can then be customized for the different displays.
The bottom line, however, is that you are using text size differences based on the screen size. The text size should be indicated in dp, so it will scale accordingly to any screen density. Really, the only resources that should be based on screen size are layouts.
If you are plan to make Multiple resolution Supporting android application just you have care about image and xml no other needs that you have same images with three different size putting in different folders like drawable-hdpi, drawable-ldpi, drawable-mdpi. you can make style.xml common for all.
Thanks

how to get same sized launcher icons on different emulator skins…(android)

have a look at figure 2. in the link given below.. http://developer.android.com/guide/practices/screens_support.html..
there it is being mentioned that ,The platform provides density independence to applications by default.(launcher icons are displayed at the same physical sizes, although screen sizes, aspect ratios, and densities are different.)
and showed with 3 emulator screens namely WVGA high density (left), HVGA medium density (center), and QVGA low density (right)...
i have created these 3 avd's and tested but the launcher icons are different in different emulator..can any one knows why it so and how should i get same sized launcher icons on those emulators...
you should refer this:
http://developer.android.com/guide/practices/ui_guidelines/icon_design.html
you have 3 different drawable folder name drawable-mdpi/,drawable-hdpi, drawable-ldpi/ in your res/ folder and each of them have different size icon. if you want same size icon in each emulator then put the same size icon in all three folders.
Keep in mind that your monitor is of a fixed pixel density, while these various devices will have differing pixel density. That means the same number of pixels will be a different physical size on your monitor than it will be on an Android device (which will typically have much smaller pixels than your monitor).

Categories

Resources