Problems in supporting multiple resolutions - android

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.

Related

Android "smallest width" layout for tablets not working

I have two activity_menu.xml one for tablets in layout-sw600dp and another in layout. The layout for tablets is never loaded (I even tested it on 4K xxxhdpi emulator). I would also add that all my layouts are portrait.
Is there anything that maybe needs to be changed in manifest, gradle or added to a file?
I didn't try layout-large, but I want to keep it "modern", not using deprecated methods.
The layout for tablets is never loaded (I even tested it on 4K xxxhdpi emulator).
I do not know what you consider 4K to be, as there seem to be multiple definitions.
However, xxxhdpi is 640dpi. 640dp is 2560 pixels at xxxhdpi density. Both 4K definitions cited on Wikipedia have the smallest width as 2160 pixels. Hence, this emulator would not use res/layout-sw640dp/, as it is not big enough.
To create an emulator that will use res/layout-sw640dp/ resources, you need to create one whose smallest width is 640dp or larger. So, for example, if you create an mdpi emulator, where 1dp = 1px, you would need to choose a resolution where both sides are 640px or larger.

Adjust view sizes in android for custom devices

I have 3 custom made android devices.
First one has a 5 inch screen with 1280x800 res
Second has a 5 inch screen with 800x480 res
Third has 7 inch screen with 800x480 res
I tried giving sizes with dp, px and inches but it seems they cant support those screens properly with the same value (even inches seems to be not exact inches but translation to px eventually).
How can i use same code to properly adjust view sizes relatively to the screen size?
Well, as first, the correct measure unit to use is: dp for controls and sp for fonts.
These are normally for margin, paddings, widths, heights, and other attributes.
Also xml drawables can take advantage of pixel independency
Define your dimensions in a res/value/dimens.xml file (this is a PROPOSED standard name, you can call it whatever you like best), in order to have them referrable from all your code, instead of being hardcoded and often repeated in many files.
Then you must know that you should provide your graphics AT LEAST in mdpi resolution (160 dpi), which will be scaled up or down to match other resolutions.
Notice that I said at least.
For every resolution you are supporting, you should add a folder in your res path containing the graphics at the corresponding density for that resolution.
this means that you will have, let's say 3 resolutions mdpi, hdpi and xhdpi (today's favourites, excluding tablets - these ones deserve some folders on their own):
The graphics is going into:
res/drawable-mdpi
res/drawable-hdpi
res/drawable-xhdpi
Just put your graphics (with the same names) with (respectively) a dpi density of 160, 240, 320 in those directories.
Now your graphics is resolution compliant.
Now, I don't realize what the problem really is.
I mean, is it the background not fitting well? then the solution is to use a tiling or an "abstract enough" stretchable picture.Or you could use 9 patches, as well
If the problem is how the fonts and other objects interact with each other, you should always reference to an mdpi device (even emulated, if you don't own a physical one). When things scale well on a mdpi device, they are supposed to scale well on every device.
For tablets in particular, you are supposed to provide specific folders for values (where you put your dimens.xml file, containing the dimensions).
These folders normally have names like values-sw600dp or values-sw720dp-land. The suffix land indicates landscape mode, the particle sw###dp indicates the minimum dimension (width or height), so, I guess that in you case you could prepare some folders called values-sw480dp and values-sw480dp-land and there you would put your dimens.xml file, with the special dimensions for that particular device.
I guess that providing only the non-land folder would be enough.

How density dependent layouts work?

How does the density dependent layouts work?
For landscape orientation only:
Two tablets -
One with mdpi density and 7inch screen size.
Other with tvdpi density and 7inch screen size.
I placed the layout1.xml in folder layout-large-land.
*The result: *
Tablet 1 with mdpi density working fine but Tablet 2 with tvdpi density layout disordered like shorter bitmap length and shorter margins for child layouts.
On account of getting this problem, I did the following change:
The layout1.xml now is in two different folders viz..
layout-large-land. and layout-large-land-tvdpi.
Now, Do I need to adjust (bitmap length and shorter margins for child layouts) manually for layout1.xml in layout-large-land-tvdpi OR will android auto adjust and set the tvdpi pixels by just seeing that its in a folder layout-large-land-tvdpi?
Your layout is mostlikely using absolute pixels, while, for sake of compatibility among variety of devices you should use device independent pixels. Also to avoid ending with blurry images (like upscalled from mdpi to tvdpi) you shall consider having your assets made for certain densities. Anyway, this is quite elementary subject and well explained in android docs: Supporting Multiple Screens

Same pixel size but different screen size and resolution

I've an android project with layouts and resources for screen size large and mdpi (resources are in folders "layout", "drawable", and "drawable-mdpi").
The layout is mostly relative but some margins are given as absolute dp values.
The screens look perfectly on a device with above specifications (large/mdpi: aka device 1) and a pixel resolution of 480x800. Now, I have another device which has the same pixel resolution of 480x800 but since the screen is smaller, it has screen size normal and hdpi (aka device 2). The screens on device 2 look really messy (elements overlap etc.)
Since the pixel resolution is identical on both devices, it should be possible to create perfectly fitting screens for device 2 as well with little effort.
If I don't care about elements physically appearing smaller on device 2, what would be the approach to just physically "scale" my layouts (to fit on device 2)?
Just copying the drawable-mdpi to drawable-hdpi helps a little bit, but there are still problems. Are the absolute dp margins in the layout the problem? Should they be replaced by pixel dependent ones and everything is OK?
In general, what are best practices when I want to use a design that was originally created for a specific pixel resolution on devices with different pixel resolutions and I don't care much about elements appearing smaller or bigger?
In my case I basically just want to "scale" the original design and I don't care much about the vertical size (because the main view is scrollable anyway).

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

Categories

Resources