Automatic layout adjustment - android

In the beginning I created my application to work on all resolutions, tested on my phone with small screen and large screen tablet.
As I had created the images for drawable-hdpi, MDPI, ldpi, each image with its resolution, he was adjusting.
However now I'm testing again on the tablet and the resolution cell is small, is only correct for the phone, she stopped to adjust the tablet increased.
Do not know if it was some setting I made in layout,
I'm using relative layout, fill_parent and wrap_content.
And in some cases put margin, and alignment, below ...
Anyone know tell me how to adjust automatically, or imagine what might be wrong?

I think you missed something about density.
Image auto scaled by os with density, as an example in lower density Image will be scaled smaller.

As lulumeya said this is for sure problem of density of tablet you are using to test
For tablet instead of putting images in "drawable-hdpi" or "drawable-xhdpi" for large screens,
put them into folder named "drawable-xlarge" in /res folder.
This folder will be used for
large screen devices such as tablets.

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.

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).

Font size outgrows while having small screen with HDPI/MDPI resolution

I am trying to support all kind of screen resolutions. When I have small screen but HDPI resolution, buttons/fonts are going out of shape. Because, I have bigger font size for HDPI screens and it goes smaller with LDPI screens. But, when small screen has HDPI resolution, android picks font size from hdpi folder and messes up font size. It becomes big and outgrows the screen width/height.
What is the best solution for such cases ? Is there any option to create folders like values-small-ldpi, values-small-hdpi (basically specifying both screen size and resolution) ?
I believe the answer to that is yes (that is, you should be able to create values-small-hdpi, etc. folders). This answer seems to support that as well.
Here is a full list of qualifiers: Resource Directory Qualifiers

Android app doesn't support multiple screens

I am working on android app, i want that this app must fit on different screen sizes and densities. I have made files.xml files in res/layout by default, res/layout-small/xml files for supporting small screens such as QVGA (low density) ,res/layout-normal/xml files for supporting medium screens such as HVGA(medium density) and res/layout-large/xml files for large screens such as WVGA800(high density). When i run app initially on medium size screen such as 320x480 i-e HVGA it runs perfectly but when i run same app on large or small screen emulator it displays same layouts which were displayed on medium size screen and doesn't fit on the screen and vice versa. I havn't use absolute layout and used dp instead of px or sp or dip. I have tried alot but couldn't succeded. How should i handle that situation? Any idea?
A few things to try,
Dump the actual screen size at run time to confirm the screen size is what you are expecting see Get screen dimensions in pixels
Temporarily remove the contents of the res/layout folder to debug where the resources are being pulled from.
Generally you should be able to support QVGA and HVGA with the same layout resource but adaptable widths and heights, eg fill_parent etc. Then have a seperate layout for tablets.

xhdpi scales images

I need explanations.
I develop an application running for Honeycomb on a tablet 10.1.
I set an image 796x1228 pixel in drawable-xhdpi folder. When this image is called directly it displayed on 1/4 of screen size. If I set this image in a layout taking all screen width and height, it scales and result is not clean.
I search a long time before testing to put this same image in drawable-mdpi folder and get a good display.
The Android documentation says that for screen xhdpi we have to put our images in a folder xhdpi, but results is really bad.
Where is my trouble ? Thanks for your explanation, information...
A 10.1" Honeycomb tablet is not xhdpi. It's an xlarge display, which is completely different. The XOOM for instance has an xlarge, mdpi display.
Are you sure your device's screen is xhdpi? Usually, devices with big screens are something like xlarge, mdpi or hdpi.
If you want just to show an image on a view you can put it into drawable-nodpi, load it and apply to your view (or let the app do it automatically).

Categories

Resources