support different screen sized - android

I have a project for an application that can run on different types of android device:
-small device :example samsung ace
-normal device:samsung galaxi s3
-tablet 10''
My layout is complex and the use of match_parent and "dp" isn't enough. I have read: http://developer.android.com/guide/practices/screens_support.html but I did not understand all of it.
Will I have to create more XML's in say, res/layout-sw720dp/main_activity.xml folder ow will I have to use different qualifiers? How exactly does it work?

For Different screen size, The following is a list of resource directories in an application that provides different layout designs for different screen sizes.
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
The following code in the Manifest supports all dpis.
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />

Kindly Use This qualifier for your Android Project with compatible screen size.
Resource Screen Size
layout-small <3 inch
layout-normal 3-4 inch
layout-large >4 inch<7.1
layout-xlarge 7.1 - 10.1 inch
If you still facing problem use this Tutorial Link

If you want to create 1 application for different devices then you have to use android different folder as defined in the sdk
for e.g
drawable-ldpi - to place the images for the low screen density devices(240*320)
drawable-mdpi - to place the images for the middle screen density devices(320*480)
drawable-hdpi - to place the images for the high screen density devices(480*800)
drawable-xhdpi - to place the images for the extra high screen density devices (above 480*800)
If you want to create application for the tablet
drawble-sw720dp - to place the images for the tablet devices(7")
drawable used to place images. you have to create the layout for different drawable folder
layout-ldpi - to place the layout for the low screen density devices(240*320)
layout-mdpi - to place the layout for the middle screen density devices(320*480)
layout-hdpi - to place the layout for the high screen density devices(480*800)
layout-xhdpi - to place the layout for the extra high screen density devices (above 480*800)
android automatically get the images and layout from the application according to the device density. but for this you have to define
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
so that application develop for the multiple screen resolution devices.

To develop an application which supports every density and resolution, we should keep following points in mind:
(1) Put different sized images(with the same name) in 4 different folders in the ratio:
ldpi : mdpi : hdpi : xhdpi = 3 : 4 : 6 : 8
(2) The sizes commonly used for these resolutions are:
ldpi = 36 * 36 px mdpi = 48 * 48 px hdpi = 72 * 72 px xhdpi = 96 * 96 px
But you can use your desired sizes for the images as well.(Just try to follow the ratio in different sizes as well.) Amongst of all these images, the image which suits the device's density , will automatically be picked.
(3) Besides this, you can also get the density of the device programmatically and set the layout accordingly, like this:
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
switch(displayMetrics.densityDpi){
case DisplayMetrics.DENSITY_LOW:
// layout for small sized devices.
break;
case DisplayMetrics.DENSITY_MEDIUM:
// layout for medium-sized devices.
break;
case DisplayMetrics.DENSITY_HIGH:
// layout for big-sized devices.
break;
}

Related

Supporting multiple screen size

I've used several images with different sizes. I copied the images into different folders.
such as (except drawable-ldpi folder):
for example :
drawable-mdpi test.png => 60*60 px
drawable-hdpi test.png => 85*85 px
drawable-xhdpi test.png => 110*110 px
drawable-xxhdpi test.png => 110*110 px
I have only one folder my layouts:
my manifest:
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true"
android:xlargeScreens="true" />
now, when I install my project on galaxy s4, images within the program shows drawable-mdpi folder. why ?
I even made ​​a separate folder for my layout and changed width and height of image :
res/layout/my_layout.xml imageview => layout_width and layout_height = 48*48 // default
res/layout-large/my_layout.xml
res/layout-xlarge/my_layout.xml
But always the default option is selected ! why?
you don't need to write support-screens in the minifest - default is fine.
first things first:
s4 is on the upper end of normal but it should still be normal not large. this is why your 'layout-large' was not used. but you should not use the size selection stuff, dpi selection is much better (so one layout should work).
s4 is on the edge between xxhdpi and xhdpi so samsung can decide what it is. i think they used xhdpi. but this should not realy matter.
dpi categories:
ldpi (you will not need it because neerly no device has it)
mdpi = 160dpi or 1x
hdpi = 240dpi or 1,5x
xhdpi = 320dpi or 2x
xxhdpi = 480dpi or 3x
simple dpi example:
if you have a fullscreen design/image in full hd (1080x1920) you can just cut the stuff out as you need it and will get it correct for xxhdpi. (if i remember correct - maybe xhdpi)
however, you can calculate the lower sizes from this point.
- xxhdpi = 1080x1920
- xhdpi = 720x1280 (/3*2 of the above)
- ...
if you do it this way it should work correct ;)

Android supporting multiple resolution with multiple layout folder

Now I'm supporting multiple resolution with multiple layout folders.
I'm using android development studio and I made 3 different folders.
layout
layout-large-port-1280x720
layout-normal-port-800x480
and I tested on 800x480 and 1280x720. 480x800 worked well, but 1280x720 follow 800x480 folder's dp and UI.
I don't know why this thing happens to me and I don't know how to solve the problem.
Why it doesn't work and what should I have to do?
For Different screen size, The following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for small, medium, high, and extra high density screens.
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
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
Thats code in the Manifest supports all dpis.
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
make sure you have given the corresponding drawables in drawable-xhdpi
I don't know on what basis you're creating the App. But it's better to avoid creating layout for specific screen sizes.. Instead you would give the following:
layout-small-port for devices like samsung galaxy y
layout-normal-port for devices like galaxy s2
layout-large-port for devices like nexus 7 which is 7 inch
layout-xlarge-port for devices having more than 7 inch size
If you specify the screen size, you can't support more number of devices
U should use:
res/layout/main_activity.xml # For handsets (smaller than 480dp available width)
res/layout-sw480dp/main_activity.xml # For phones (480dp wide and bigger)
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)
res/drawable – The default image folder
res/drawable-sw200dp
res/drawable-sw600dp
res/drawable-sw800dp

Android - Setting for Tablets

I am pretty new to Android. I wanted to know that if i want to design a tablet application then what changes i want make in the existing code which i designed for normal phone.
I did the Research and found,
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
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
and in Manifest
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
Is it all done?? or I want to change something other than this??
You need to create new layout files for tablet versions, Java part is enough but layouts and image drawables are the main things you need.
Go through Supporting Multiple Screens, Here you will have a complete idea about how to create UI supporting Tablets and their res folders.
For all tablet resolutions check this link
below are the available resolutions for android mobile and tablet
1 2560*1600
2 1366*768
3 1280*800
4 1280*768
5 1024*768
6 1024*600
7 960*640
8 960*540
9 854*480
10 800*600
11 800*480
12 800*400
13 640*360
14 640*240
15 480*320
16 400*240
17 320*240
Most Common tablet resolutions are
Samsung Galaxy Tab 10.1 3G - 10.1 inches, 1280 x 800 pixels
Samsung P1000 Galaxy Tab - 7.0 inches, 600 x 1024 pixels
For application to be worked, this is enough. But you should take care the size of the application When you are adding images to drawable folders it will increase your project size. So if you are using same images for all screens put that image in drawable folder. It will pick automatically to all screens, and if you want different image for different screen size put in different layout folders. You can make different layouts according to screen size to be fitted. The android will automatically pickup the proper xml files.
add layout-large-hdpi folder to ur resources and copy the files from layout to created one,
all ur created layouts will automatically converted to tablet screen size

Android interface implementation for multiple screen sizes and densities

I'm developing an application and i need it to fit all screen sizes and densities.
I created 4 folders for the resources (drawable-ldpi,drawable-mdpi,drawable-hdpi,drawable-xhdpi) and 4 xml layouts. But i'm confused a little about many points:
1- If I have a Samsung Galaxy tab 10.1 (mdpi screen) with a 1280 x 800 screen size and a Samsung Gio (mdpi screen) with a 320 x 480 screen size, how can I make the "layout-mdpi" folder including the xml layout file for medium dpi, fits these 2 devices having the same dpi but 2 different screen sizes (Galaxy tab is much bigger than Samsung Gio)?
2- I'm creating my png's using Photoshop, these png's must be saved with 320dpi,160dpi,240dpi..? Or all the resources must be saved in 72 dpi but different sizes?
3- I tested a star icon on my Samsung Galaxy tab 10.1 (mdpi screen) having 32x32px size, dunno why my icon is blurred!
You have to make all 4 different sizes images and put that images according to folder.And also set the property in menifest like this.
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />

support for multiple resolution android

My app has 2 different resolution support, 480x800 and 320x240, i have created folder for them for instance layout-normal-hdpi and layout-normal-mdpi. But somehow emulotor is not picking up the ui for hdpi. I have created different layout aswell.
the way i am dealing with multiple screen is this way and its working fine.....if any one has improved wayso do guide me
Screen size 480x800
layout-normal-hdpi-480x800
drawable-normal-hdpi-480x800
Screen size Galaxy Nexus---
though its size is 1280x720 but in actual due to system bar its dimension(screen size) differs
layout-normal-xhdpi
drawable-normal-xhdpi
Screen size Note 5.3---
layout-normal-xhdpi-1280x800
drawable-normal-xhdpi-1280x800
Screen size S3---
layout-normal-xhdpi-1280x720
drawable-normal-xhdpi-1280x720
Screen size 7inch tab 2 supporting OS version 3 and above---
dont write dimension 1026x600 bsz in actual due to system bar its dimension(screen size) differs
layout-large-mdpi
drawable-large-mdpi
Screen size 7inch tab p1000 etc supoorting os verion less than 3---
layout-large-hdpi-1024x600
drawable-large-hdpi-1024x600
Screen size 1280x800 tab 10.1,10.2,note 10.1 etc---
you can add dimension if you want other wise it is fine
layout-xlarge-mdpi
drawable-xlarge-mdpi
From the documentation:
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
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
layout-normal-mdpi does not exist. Use layout-mdpi instead.
For reference: http://developer.android.com/guide/practices/screens_support.html
The Api level must also support this: Android - layout-large folder is been ignored
Handling different resolutions can get tricky on Android.
The one true resource for this is the official site:
http://developer.android.com/guide/practices/screens_support.html
It sounds to me like you might be confusing the size with the pixel intensity here.
Try to create the folders:
res/layout-sw480dp/main_activity.xml //for the large screen
and
res/layout-sw320dp/main_activity.xml //for the small one
Do you also have different drawable resource folders? Did you manage to get them to work?
Android Support Multiple Screeen
for tablet
Resolution 1280x800/1280x720
values-sw720dp
drawable-sw720dp
layout-sw720dp
Resolution 1024x600
values-sw600dp
drawable-sw600dp
layout-sw600dp
Resolution 480x800(twinner resolution, mdpi in tablet & hdpi in mobile)
values-large-mdpi
drawable-large-mdpi
layout-large-mdpi(incase you want to make separate layout)
for moblie
Resolution 1080x1920
values-sw360dp-xxhdpi/values-sw360dp-notlong-xxhdpi (when 768x1280 is used)
drawable-xxhdpi/drawable-sw360dp-xxhdpi/drawable-sw360dp-notlong-xxhdpi(when 768x1280 is used)
layout-sw360dp
Resolution 720x1280
values-sw360dp-xhdpi
drawable-sw360dp-xhdpi
layout-sw360dp
Resolution 768x1280
values-sw360dp-notlong-xhdpi
drawable-sw360dp-notlong-xhdpi
layout-sw360dp
Resolution 540x960
values-sw360dp-hdpi
drawable-sw360dp-hdpi
layout-sw360dp
Resolution 480x800
values-hdpi
drawable-hdpi
layout-hdpi
Resolution 320x480
values-mdpi
drawable-mdpi
layout-mdpi
Resolution 240x320
values-ldpi
drawable-ldpi
layout-ldpi
tags to add in manifest if your app needs to support full hd device only
for 1080x1920
<screen
android:screenDensity="480"
android:screenSize="normal" />
Courtesy: (Maulik Joshi)

Categories

Resources