So I have two phones Note 3 (5.7in 1080p) here is a screenshot of the app:
And I also have A7 2018 (6in 1080x2220 18.5:9) here is a screenshot:
After seeing the massive difference how can I make stable UI across multi-screen sizes and resolutions, and what makes the situation even worse is Android Studio's preview lack of precision.
like is there any way to create something like separate XML layouts for separate classes of display?
This link from the official docs will help you.
Things you can do to support different screen sizes are:
Avoiding usage of absolute values
If you use absolute values, use dp for sizes and sp for font sizes
Use match_parent or wrap_content whenever possible
If you use a ConstraintLayout Guidelines will probably be your friend (can create them % based)
If nothing of the above helps, create a seperate layout for a different screensize (explained here)
It's either use ConstraintLayout with GuideLines or use different layouts for different screen sizes.For example, you can create a layout named main_activity that's optimized for handsets and tablets by creating different versions of the file in directories as follows:
res/layout/main_activity.xml # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
Here's how other smallest width values correspond to typical screen sizes:
320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
480dp: a large phone screen ~5" (480x800 mdpi).
600dp: a 7” tablet (600x1024 mdpi).
720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
Check out the docs:
https://developer.android.com/guide/practices/screens_support#DeclaringTabletLayouts
Related
Android runs on a variety of devices that offer different screen sizes and densities. For applications, the Android system provides a consistent development environment across devices and handles most of the work to adjust each application's user interface to the screen on which it is displayed. At the same time, the system provides APIs that allow you to control your application's UI for specific screen sizes and densities, in order to optimize your UI design for different screen configurations. For example, you might want a UI for tablets that's different from the UI for handsets.
This leads us to this question what are the best qualifiers to use from the list bellow:
A set of six generalized densities:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
Or
sw600dp
sw720dp
w720dp
w1024dp
h720dp
h1024dp
or
A set of screen size :
small
normal
large
xlarge
I suggest to use
sw600dp
sw720dp
w720dp
w1024dp
h720dp
h1024dp
because with those you can control exactly how it looks, while making it easier for you quickly tell the values.
In addition, this is the more "modern" way of defining sizes.
From developer.android.com:
One of the difficulties developers had in pre-3.2 Android devices was
the "large" screen size bin, which encompasses the Dell Streak, the
original Galaxy Tab, and 7" tablets in general. However, many
applications may want to show different layouts for different devices
in this category (such as for 5" and 7" devices), even though they are
all considered to be "large" screens. That's why Android introduced
the "Smallest-width" qualifier (amongst others) in Android 3.2.
The Smallest-width qualifier allows you to target screens that have a
certain minimum width given in dp. For example, the typical 7" tablet
has a minimum width of 600 dp, so if you want your UI to have two
panes on those screens (but a single list on smaller screens), you can
use the same two layouts from the previous section for single and
two-pane layouts, but instead of the large size qualifier, use sw600dp
to indicate the two-pane layout is for screens on which the
smallest-width is 600 dp.
I'm developing a game for mobile devices and have come to the point where I need to adapt it to different aspect ratios.
I've looked around for the common Android aspect ratios but most resources only list the DPI value.
Anyone know any resources I may have missed, or might happen to know the common aspect ratios off the top of their head?
Typically I'm not a fan of providing links as answers, but there is a community wiki here on SO that is maintaining a list of Android aspect ratios. It contains 30+ devices so far.
Found here: Is there a list of screen resolutions for all Android based phones and tablets?
320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc). = 3:4
480dp: a tweener tablet like the Streak (480x800 mdpi). = 3:5
600dp: a 7” tablet (600x1024 mdpi ~= 640x1024). 10:16
720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc). 9:16
from: http://developer.android.com/guide/practices/screens_support.html
also: http://en.wikipedia.org/wiki/Comparison_of_Android_devices
I made an app earlier which was all good, at the time of development there were only two devices in the market galaxy note and samsung nexus, now devices with resolution 720*1280 are around 30, when my app runs on these devices they go to left corner leaving the empty space behind, layout folder name were created were layout-small, layout-large, layout-normal,
As far I know xlarge is for tablets, my question is what will be the layout folder name for devices having 720*1280 resolution, and what dpi in width they have, like in normal screen the width is 320dp , what will be in hd devices.
Edit : another thing sw360dp works fine on ICS, jelly beans does not pick resources from it. :/
Try using folder name with /layout-sw360dp/ and width 360dp
For devices having 720 * 1280 resolution, you can use layout-sw720dp folder
More info is provided in the official documentation (see Configuration Examples)
To help you target some of your designs for different types of
devices, here are some numbers for typical screen widths:
320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
480dp: a tweener tablet like the Streak (480x800 mdpi).
600dp: a 7” tablet (600x1024 mdpi).
720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
For other cases in which you want to further customize your UI to
differentiate between sizes such as 7” and 10” tablets, you can define
additional smallest width layouts:
res/layout/main_activity.xml # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml # For 10” tablets (720dp wide and bigger)
I'm creating an Android application. The main activity layout will have a background image that will wrap with the whole screen. What resolution should I use to create the background image? What about DPI? I need it to be compatible with all devices
(for example the HTC Sensation screen's resolution is 540 × 960 pixels).
The best way for you is to start reading this article, it contains the best practices for supporting multiple screen sizes and densities.
EDIT:
I use the following directories to store the drawables for maximum size and density optimization:
Small screens support
drawable-small-hdpi
drawable-small-ldpi
Normal screen support
drawable-normal-mdpi
drawable-normal-hdpi
Large screens support
drawable-large-mdpi
Tablet screen support
drawable-xlarge-mdpi
Of course not every time this solution is the best, aqs's solution is more common used. You can follow this site to track which screen sizes and density's are most used and decide which of the screens worth support for your application. And of course you can read about the Providing Alternative Resources to understand better what are your options.
You should read Supporting multiple screens. You must define dpi on your emulator. 240 is hdpi, 160 is mdpi and below that are usually ldpi.
Extract from Android Developer Guide link above:
320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
480dp: a tweener tablet like the Streak (480x800 mdpi).
600dp: a 7” tablet (600x1024 mdpi).
720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
IMHO answer of #Cata is a bit misleading because of mixing screen size and screen density for providing graphics.
I think the best practice is to distinguish this two things by providing:
different size images (PNGs) for different densities and
different layouts for different generalized screen sizes.
By doing so developer can reduce number of different images to 4 categories (ldpi, mdpi, hdpi, xhdpi) if he wants to support all currently existing densities. Of course XML layouts files for different (small, normal, large, xlarge) screen sizes are necessary if we support them but it is much easier to make/edit/correct/adjust xml files than PNGs.
A bit more details and explanation u can find in my previous answer about this topic on this link.
Hope u find this answer useful. Cheers.
I created 4 different layout files and placed it in layout , layout-small,layout-large,layout-xlarge. folder and
TESTED IN QVGA,HVGA,AND WXGA EMULATOR.
But it is only taking the default layout(which i placed it in layout folder)for all emulator. Any solution?
Have you given the same name to all layout file, for e.g. main.xml, i mean to say give the same name to xml layout files and places in the particular folder. It will automatically managed by Android itself, programmer need not to bother about the same.
I made my comment as answer as this is right as per vnshetty's comment above. So that other answers may not be selected as accepted wrongly.
To help you target some of your designs for different types of devices, here are some numbers for typical screen widths:
320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
480dp: a tweener tablet like the Streak (480x800 mdpi).
600dp: a 7” tablet (600x1024 mdpi).
720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
For other cases in which you want to further customize your UI to differentiate between sizes such as 7” and 10” tablets, you can define additional smallest width layouts:
res/layout/main_activity.xml # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml # For 10” tablets (720dp wide and bigger)
http://developer.android.com/guide/topics/resources/providing-resources.html
layout-medium does not exist - should use layout-normal instead
Also are you specified min api version? it will works only if you specify <uses-sdk android:minSdkVersion="4" />
or higher in your manifest file.