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
Related
I've developed an interface and everything has used dp settings so I thought it should have been good for most screen sizes. However when testing it gets messed up on most screen sizes, bigger and smaller. I get the icons not showing right since I only have one set for Nexus 4 size and density as they are only placeholders until I build the proper icons at the proper scales.
What is going wrong? Is dp the wrong way to go about designing it for scale? I've considered designing specific layouts for various screen sizes but I'm not sure where to begin in regards to what to target.
Here is what is should look like. (Nexus 4)
Smaller Screen (Nexus One)
Bigger Screen. (Nexus 5) - See how the text collides with the vertical divider.
dp - an abstract unit that is based on the physical density of the screen. which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use.
It doesn't mean that image can scale automatically. It works in the specific density devices well.
Generate ur icons with http://romannurik.github.io/AndroidAssetStudio/icons-generic.html and place the icons and check.
For text don't use dp : instead use sp
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.
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.
I am developing for android and my code runs perfect on nexus or any 3.7 inch device.
If I run it on tablet (7 or 10.1 inch) then the fonts and buttons are very small and the spacing is way too big.
If I run it on 2.7 QVGA then the buttons are too big and overlap.
I am using dp and sp all over the layout so I am surprised it didn't adjust according to different screen size/density.
Does that mean that I have to wrte the same XML layout in 3 layout folders (large, medium and small) and put my drawable in 3 different density folders?
Or am I amissing something here. Yes I read the "Supporting multiple screen" document and it just loses me with the details (but I did follow the tips of using dp and sp). I am looking for more of a summary/general approach answer.
dp and sp adjusts according to screen density. Therefore, a screen with 500 dpi and 4000 dpi but with the same SCREEN DIMENTIONS will looks the same.
If they have different screen sizes, it won't fit as you want. If you want to support multiple screen sizes, you'd have to use weights or percentages.
The key is that dp = device independent pixel and it only adjusts according to density, not screen size.
In the most cases if you don't make a tablet app, you don't need to make more than one XML layout for different densities/sizes. All you must do is define dimensions with DP and SP as you said.
But is necessary to provide different images in the drawable folder to show one or other in function on screen size/density.
If you put all images in drawable folder (without specify hdi,ldi or mdi) Android will try to adjust the images but not always works fine.
Hope it helps.
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.