Background images for different screens - android

In my application I have a background for activity. This is an image, I am going to use fitXY for it. I am ok if it will be resized a little (keeping aspect ration is not very important) but not very much.
I am going to prepare few images with different size and for both Portrait and Landscape orientation. I am going to cover about 90% of devices.
My question is the following:
What images sizes I need for background?
What folders under "res" I should put these images?
I would like to get very specific file sizes and folder name where to put these files.
The solution should work on tablets as well.

I just used two images with maximum sizes (one portrait and one landscape). Then android resized the to smaller and it looks quite good for me.
I have one background with resolution: 800*1200 px in drawable folder
and another with resolution: 1200*800 px in drawable-land folder
This works pretty fine on tablets.

You have to create multiple resources for your app. Android has 4 resolutions (ldpi,mdpi,hdpi and xhdpi) and 4 generalized screen sizes (small, medium, large and extra large). So you have to make 4 layouts (or 3 if you don't plan on supporting tablets, since tablets come under the extra large category) to support the screen sizes.
Here's a general guide:
put layouts for small, medium, large and extra large in your res/ folder as follows:
res/layout/sample_layout.xml // default layout
res/layout-small/sample_layout.xml // layout for small screen size
res/layout-large/sample_layout.xml // layout for large screen size
res/layout-xlarge/sample_layout.xml // layout for extra large screen size
you can also use
res/layout-land/sample_layout.xml for landscape orientation for all screen sizes or you can target landscape layouts for specific screen sizes as res/layout-medium-land/sample_layout.xml
note that all the layouts have the same name.
once you have your layouts ready, you need to take care of image resolutions also
once again in your res/ folder add images like this:
res/drawable-ldpi/sample_image.png // low density
res/drawable-mdpi/sample_image.png // medium density
res/drawable-hdpi/sample_image.png // high density
res/drawable-xhdpi/sample_image.png // extra high density
once again, all the images have the same name.
general guidelines for designing images are:
ldpi is 0.75x dimensions of mdpi
hdpi is 1.5x dimensions of mdpi
xhdpi is 2x dimensinons of mdpi
generally, I design mdpi images for a 320x480 screen and then multiply the dimensions as per the above rules to get images for other resolutions.
Android will automatically select the best combination of layout and image depending on the device. For example, for a high resolution medium size device, layout-medium and high density image will be displayed to the user.
Make sure you create emulators for all these combinations and test your app thoroughly. here's the official docs for more info:
https://developer.android.com/guide/practices/screens_support.html

m/h/xh dpi are the most important. Combine that with the (most common) resolutions and you should be fine for your "90%" target.

Related

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

Do I need to design background for each device size?

Dear All I’m going to work in android application I should design the interface. I read articles on http://developer.android.com/design/index.html but I still have some missing point.
Do I need to design back ground for each device size ?
Check for this Link for supporting multiple screen. This link will show you how to create the different layout for different screen size devices.
But even if you want to make a Unique layout for supporting multiple screen in orientation or portrait mode then,
For image, use 9 patch images.
Here is the link http://developer.android.com/tools/help/draw9patch.html
For width and height of any widgets, use wrap_content or match_parent or you can use android:layout_weight and android:weightSum
Avoid using the pixels i.e. px
Use dp
By this you can create the unique layout working for multiple screens, but that screen should be in orientation or portrait mode.
If you want to support for for both,then you have to createlayout-landfor landscape mode in the res folder.
Actually, you should. There are 4 main screen sizes in android those get layout xmls from res/layout-xlarge, res/layout-large, res/layout-normal and res/layout-small. At the same time, you should use different image resolutions for different screens those get images from drawable-hdpi, drawable-xhdpi, drawable-mdpi and drawable-ldpi.
It depends on the background type. If your background is an image with high resolution you should provide different images for different screen sizes if the whole background is an image.
You can also:
Make background from tiles (like icloud.com)
Specify a ninepatch image if your image is something like a frame where corners should remain the same and the body should be scaled (not very good if you have some picture)
Specify multiple different images for different screen resolutions and densities. To do so read supporting multiple screens. If you need even more precision in image scaling and quality you can use the fundamental size of screen attribute which is sw<N>dp - you can specify the smallest width of the screen where your image should be used. This is a qualifier name for a resource folder.
Some values you might use here for common screen sizes:
320, for devices with screen configurations such as:
240x320 ldpi (QVGA handset)
320x480 mdpi (handset)
480x800 hdpi (high density handset)
480, for screens such as 480x800 mdpi (tablet/handset).
600, for screens such as 600x1024 mdpi (7" tablet).
720, for screens such as 720x1280 mdpi (10" tablet).
You should also have a look at other qualifiers that make Android choosing image at runtime (screen density, Available width, Available height, Screen size or Screen aspect). By combining these qualifiers and testing carefully you will be sure that the user has the best experience on each device.

xml for multiple screen in android

i am working on 2.2 version of android and xml is designed according to this version
Specification of emulator : version 2.2, Built-in : HVGA , Memory : 1024
and now i need this application to be transformed into 4.0 version of Samsung galaxy s3 but the screen are very streched and does not look good
thanks in advance if any help.
You have to create multiple resources for your app. Android has 4 resolutions (ldpi,mdpi,hdpi and xhdpi) and 4 generalized screen sizes (small, medium, large and extra large). So you have to make 4 layouts (or 3 if you don't plan on supporting tablets, since tablets come under the extra large category) to support the screen sizes.
Here's a general guide:
put layouts for small, medium, large and extra large in your res/ folder as follows:
res/layout/sample_layout.xml // default layout
res/layout-small/sample_layout.xml // layout for small screen size
res/layout-large/sample_layout.xml // layout for large screen size
res/layout-xlarge/sample_layout.xml // layout for extra large screen size
you can also use
res/layout-land/sample_layout.xml for landscape orientation for all screen sizes or you can target landscape layouts for specific screen sizes as res/layout-medium-land/sample_layout.xml
note that all the layouts have the same name.
once you have your layouts ready, you need to take care of image resolutions also
once again in your res/ folder add images like this:
res/drawable-ldpi/sample_image.png // low density
res/drawable-mdpi/sample_image.png // medium density
res/drawable-hdpi/sample_image.png // high density
res/drawable-xhdpi/sample_image.png // extra high density
once again, all the images have the same name.
general guidelines for designing images are:
ldpi is 0.75x dimensions of mdpi
hdpi is 1.5x dimensions of mdpi
xhdpi is 2x dimensinons of mdpi
generally, I design mdpi images for a 320x480 screen and then multiply the dimensions as per the above rules to get images for other resolutions.
Android will automatically select the best combination of layout and image depending on the device. For example, for a high resolution medium size device, layout-medium and high density image will be displayed to the user.
Make sure you create emulators for all these combinations and test your app thoroughly. here's the official docs for more info:
https://developer.android.com/guide/practices/screens_support.html
You have to maintain your xml files in
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
Check this Supporting Multiple Screens for how to design your layout for supporting multiple screens
and also for images use
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density

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, concerning the User Interface design

the more I read the Supporting Multiple Screens guide, the more I get confused.
if the layout folder's qualifier is based on size (small, normal, large and xlarge) and the drawable folder's qualifier is based on density (ldpi, mdpi,hdpi and xhdpi),
then how can I specify the size of the drawables/images??
should all the images inside the drawable folders have the same size (based on the normal screen size) but different densities (i.e. pic.png inside drawable.ldpi has the same width and height of pic.png inside drawable.mdpi but has different density)??
the problem is that each screen size may include the three densities (i.e. a large screen may be ldpi,mdpi or hdpi).
.how can I be designing the images on size basis and on density basis on the same time??
thank you.
36x36 for low-density
48x48 for medium-density
72x72 for high-density
96x96 for extra high-density
http://developer.android.com/guide/practices/ui_guidelines/icon_design.html
hope this helps.
In general you'll want the smallest pictures in ldpi, middle ones in mdpi, and larger in hdpi etc...
Even though it is technically possible for a device to have a "large" screen and an "ldpi" density manufactures have tended to stick to making devices with big screens be higher density as well.
EDIT:
The images only need to be designed with density in mind. Because if you take the same 100x100 pixel image and show it at 3 different densities it will appear largest (to human eyes) on the smallest density. So to account for that you make 3 images, lets say one 80x80, one 100x100, and one 120x120. Now if you show those 3 images across 3 densities the size that object appears to be to your eyes will be much closer than before.
the large, medium, small etc... qualifiers that you can add to the layout folders are not so much about any image resources themselves, but rather structuring the View components on the given page so as to make best use of the space available.
For instance, if your application has a list of items to choose from in it. On a tablet (large or xlarge) screen it may look nicer and be more effecient to have two or more columns of items displayed in your list on the screen. Whereas on a handset there may not be enough width (in portrait mode) to fit more than 1 column in. So to handle this situation you'd put a layout xml file inside the layout-normal folder that has a single column ListView. Then put another layout xml file in the layout-large folder that uses a GridView so that it can have an additional column
This image will show you roughly which folder the system will pull your images and/ or layout xml files from given the screen size and density.:
All of your image resources go in the drawable folders which are qualified with the densities. (ldpi, mdpi, hdpi etc)
The layout folders are what get qualified with the screen size (small, normal, large etc) The layout folders will contain xml layout files only, no images.

Categories

Resources