Android Multi Screen - android

Today, i read much information on android's multi-screen document. I doubt that android support multi-screen on QVGA, HVGA and WVGA when you use 'dp' unit on the xml layout.Does the android support the same density but different resolution? For example, i define a xml layout for mdip. Can this layout be used on 480x800 and 320x480 resolution?
Thank You.

To answer your question: Yes, that layout could be used on various resolutions.
If you're using density based layouts and drawables, they can be used across all kinds of screen sizes. Examples of mdpi (160):
Normal screen: HVGA (320x480)
Large screen: WVGA800 (480x800), WVGA854 (480x854), 600x1024
Xtra large screen: WXGA (1280x800), 1024x768, 1280x768
They might be different resolutions, but the density is approximately the same (mdpi). If you want to create layouts for each specific screen size, you can use normal-mdpi, large-mdpi and xlarge-mdpi.
There's a lot of information available on the subject at the Android Developer site: http://developer.android.com/guide/practices/screens_support.html
I'd suggest you go ahead and do a lot of testing with the various SDK templates. That helped me a lot when I was in your situation.

It does depend on how you specify your layout, and it might or not suffice specifying a single layout.
A dip is no more than a measure which scales depending on the type of a screen.
If for instance, you determine that a view has a height of 400dip, it will represent 400px in a mdpi screen, 300px in a ldpi screen and 600px in a hdpi screen.
Since you'll get around a lot by using relative constraints (such as fill_parent/match_parent or wrap_content) and relative positioning, most layouts will actually scale without you needing to do anything.
If you find yourself a lot needing to manually specify your layout element sizes, you might eventually stumble into a few layouts that you might need to rethink or to reimplement.

Related

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.

Density-specific layouts vs. size-specific layouts in Android

For quite a long time, I have been declaring resource folders for 4 different densities:
drawable-ldpi
drawable-mdpi
drawable-hdpi
drawable-xhdpi
In the layout's XML, I have been using fixed widths (while still density-independent) such as 128dp for those graphics.
However, when more and more large-screen phones, and especially tablets, were introduced, that approach did not work anymore. Although you provide density-independent resources this way, the layout will not look good on large screens.
This is why I think I need to add Dimension resources that depend on the screen size, for use in the XML layouts, e.g.:
values
values-w600dp
values-w720dp
values-w1024dp
But does that mean that I should drop supporting those 4 density containers? Or do I need to provide 16 resource folders, i.e. one for every combination of density and size?
I can't find any good help in the Android documentation as to this topic.
drawables and layouts are different. To answer your question, should you stop support those densities. Yes, but you should still support xdpi and hdpi. Romain Guy recently said that modern devices like the Nexus 7 (at a tvpi) can scale the assets properly enough that mdpi isn't really needed. And nobody uses ldpi anymore. Last I looked is was less than 2% of the market.
About layouts. A Nexus 7 (1280x800 tvdpi) would use something from the values-w1024dp but still get assets from the drawable-hdpi folder. Those two aren't mutually exclusive. Something like a S3 would also pull from the values-w1024dp but use drawable-xdpi. You only need to provide an alternative layout if your use-case calls for it.
So do you need 16 different things? No. You do need xdpi & hdpi (if not mdpi). You may want to include alternative layouts for different sizes. You can be as specific as you want or as generic. Unless you're doing a hybrid app for both phone & tablet (7 & 10 in) you probably don't need a lot of xxxx-sizexxx folders.
In the layout's XML, I have been using fixed widths (while still density-independent) such as 128dp for those graphics.
This is probably a source of your issues. Your layouts should be as fluid as possible using wrap_content and match_parent. Fixed sizes should be reserved for padding around the sides and image where you know the size ahead of time. If you do this, your layout should look decent at any size from a small 320 x 200 to a GTV size.
1) Regarding dimensions in your layouts (values/dimens.xml):
values values-w600dp values-w720dp values-w1024dp
But does that mean that I should drop supporting those 4 density
containers? Or do I need to provide 16 resource folders, i.e. one for
every combination of density and size?
No, you don't need to provide different dimensions per dpi bucket (hdpi/xhdpi), because the dimensions are already being scaled up or down based on the device (if you're using dp instead of px). So for dimensions, you only need to provide values for devices with different sizes (hence the name, values-smallest possible width-600-dp). Because you don't want 16dp padding on a phone AND 16dp on a 10" tablet as well. You'd want 64dp instead. And no, it doesn't matter what density the device has. It still needs to have the same padding on the respective device width. So for dimens, you only need to think about the device's actual physical dimensions.
2) Regarding drawables scaling for different resolutions (drawables/xdpi):
The system scales them appropriately for the device. You don't need to worry about this. Also, you don't need to add any other buckets here. Just use mdpi/hdpi/xhdpi and maybe xxhdpi because many new devices are going to use the new density in the future.
Conclusion: there are 2 different UI building components that vary according to 2 different rules: drawables based on screen density and dimensions based on screen size. Do not mistake one for the other and think you need tens of buckets in the values folder, because that's not only wrong, it's just mind boggling.

Multi Screen Support with dip/dp in Android?

Assume that I am defining a button or text view width as 100 dip and height as 30 dip in XML file. As for As I know, Android itself take care of that button or text view appearance proportionate or same among ldpi, mdpi or hdpi devices as I defined dimension in dip. This is one of the recommendations, if you want to provide multi screen support. My Question is does dip is only useful in handling ldpi,mdpi or hdpi devices with same width and height means all 320X480 or all 400X840 like that or is it also support across multi screen dimensions means If I define a button with 100X30 dip for 320X480 device, after adding all screen support true in manifest file, android system it self will recalculate the widget size to some 200X60 dip to 700X1024 device.
If dip does n't work across multiple screen sizes(if device physical sizes are different) then I need to write sepearte layout file for each devices where I can't define my complex layouts with Linear Layouts with some weights, correct me if I wrong. Are there any alternatives, suggest me. Thanks In Advance.
dip is "density-independent", so these measure units are tied to density and not the screen size. For example, there are 10" tablets that are still mdpi, and of course layouts that look well on small mdpi phones will look terrible on those devices. The workaround here is to use dimension values and override them for such cases. Now, instead of using, for example, 10dip inside your XML, you will be using #dimen/dip_10, which will have different values in values/mdpi and values/xlarge-mdpi. Hope this helps.

The measurement independent of the LDPI,MDPI,HDPI

Can any one tell me whether is there any unit in android such that if I set the value of a margin/padding with a value,then that will be automatically adjusted in the other type of devices.
For example- If I set the margin/padding as 10dip based on HDPI then the alignment wont be OK in mdpi or ldpi with the same code.
I seached about this but couldnt find any solution.
MDPI, LDPI, HDPI etc... Specifies the resolution (pixel density) of a device. It Has nothing to do with the physical size of the screen. You can have small phones with an XHDPI screen, and big tablets with LDPI and the other way around.
If you want to size items relative to the size of the device, you can raise the LayoutWeight of the widgets. The left over space on the screen is distributed over the widgets with nonzero weight.
First of all i suggest you to use 8dp as common padding/margin between your views it is standard and now as you said you need a measure that automatically resize the space you mentioned according to the screen size. right? they you should consider using small/normal/large/xlarge instead of ldpi/hdpi. for more information i suggest you go through this guidelines http://developer.android.com/guide/practices/screens_support.html

How should I provide alternative resource for qHD(540x960 resolution with 256 dpi) screens

I have designed attached screens for my app. The app targets android 1.6 and above. Currently the app is running on majority of hdpi and mdpi devices and few devices having some odd resolution like 1024x600 with 169 dpi, 1024x600 with 179 dpi, 1024x600 with 240 dpi. I have provided alternative layouts to support multiple screens in below mentioned folders.
layout: Default layout resources.
layout-hdpi: For hdpi screens. Few layouts in my projects need to be specifically optimized for this.
layout-mdpi: For mdpi screens. Few layouts in my projects need to be specifically optimized for this.
layout-large: Default layout resources for large screens.
layout-large-hdpi: Layout resources for hdpi screens having resolution 1024x600
layout-sw400dp-v11: This is mainly for 7" tablet. Only devices running Honeycomb or above can recognize this.
Now I also need to add support for qHD screens(540x960 having 256 dpi or similar). Below is the example screen I need to design and add support for qHD screens. This screenshot is taken on HTC Incredible S having resolution of 480x800 with 240 dpi.
I have designed layout for qHD screens so that it will look same on those screens as well.
Now, I have below questions:
1. Am I having right directory structure for providing alternative resources considering I need to support hdpi, mdpi and above mentioned odd screens? If not, how should I provide alternative resources as for those screens? I really need to design separate file so that the UI looks the same across multiple screen resolutions and densities.
2. qHD Screen are having 256 dpi. That means those screens are hdpi screens. I already have resource for hdpi screens which looks as above on most of the devices. but when I view it on qHD screens, it looks like below screenshot. So, how do I provide alternative resource for qHD screen such that it won't affect my current layout resources which are showing good on most of the devices?
#Espiandev
A qHD, hdpi device has a display-independent pixel (DIP) screen size of 360x640, whereas the Incredible S's is 320x533 hence why some of the images are higher up the screen relative to others. So essentially, the qHD device can show more stuff that the Incredible S, per screen. See here for an explanation of DIPs and some more tips
-- Thank you for this insight. I am aware of this. Also I have read post by Dianne Hackborn,; "New Tools For Managing Screen Sizes" - http://android-developers.blogspot.in/2011/07/new-tools-for-managing-screen-sizes.html
From what it looks like, you're currently using some margin or padding above the goal/gain/to go parts, I'd instead suggest changing their gravity to bottom (i.e. align them to the bottom of your screen) and then use a margin or padding below the item.
-- No I am not using padding or margin for these parts. Its a relative layout where goal/gain/togo buttons are below that meter tape button. As you have suggested setting gravity to bottom and have bottom padding; yes, I had tried that as well but then distance between that meter tape button and these circles increase and I have to modify sizes and margins between those glasses, button below that and meter tape button which created different layout file. When you view this screen on small screen devices, views will overlap as small screen devices can show less views.
But I'd work on making your app adaptable to screens rather than trying to divide screen sizes up like this, as you shouldn't really need separate layout resources for mdpi, hdpi etc.
-- I agree that Normally I shouldn't need separate layout for mdpi and hdpi screen. But the requirement here is that screen should look exactly the same on all screens. Like, all views within that yellow circle should not go outside of that circle. That button at the center should be always at the center. Also, the relative sizes of those 3 little circles at the top and below meter tape button should be same. This left me no choice than creating different layout for mdpi and hdpi screen.
I have created different layout file for qHD screen. Now my question is where do I put that so that qHD devices will use that file and other devices will continue to work as those are working now.
A qHD, hdpi device has a display-independent pixel (DIP) screen size of 360x640, whereas the Incredible S's is 320x533 hence why some of the images are higher up the screen relative to others. So essentially, the qHD device can show more stuff that the Incredible S, per screen. See here for an explanation of DIPs and some more tips.
There's no real way to make the UI look exactly the same on the Incredible S and qHD devices. Unlike iOS devices, screen sizes are very varied. From what it looks like, you're currently using some margin or padding above the goal/gain/to go parts, I'd instead suggest changing their gravity to bottom (i.e. align them to the bottom of your screen) and then use a margin or padding below the item. That way it will hopefully stay aligned with your lunch/dinner boxes. If you post your XML file, that will help diagnose the problems.
Before Android 3.2, I don't believe there is a way to distinguish the two cases above, but after 3.2, you can use the swXXXdp (shortest width) attribute. But I'd work on making your app adaptable to screens rather than trying to divide screen sizes up like this, as you shouldn't really need separate layout resources for mdpi, hdpi etc.

Categories

Resources