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
Related
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
So I used the following code below to have my application to scale screen size on different android devices but when I am testing on my Nexus 7 its does not scale and its as if it was on a 4 inch screen. When I run it in the emulator on a 7 inch screen it works. Anything wrong with my manifest file?
<supports-screens
android:resizeable="true"
android:smallScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:normalScreens="true"
android:anyDensity="true"
/>
this code goes right before the "application" part right?
Ok, so what you have to know is that support-screens doesn't make your application look 'nice' on screens you are supporting (check this link). It just tells that users with such screens will be able to download your application, but it's up to you to make it display properly. You have to create layouts for specific screens on your own.
More about it you can read in Android's documentation: http://developer.android.com/guide/practices/screens_support.html
Basically, you have to properly name your directories in which layout files are stored in order to let Android know which one should it pick up for specific device. If for example your layout's file was "layout.xml" you should have:
/res/layout/layout.xml // Default layout
/res/layout-small/layout.xml // Small screens
/res/layout-large/layout.xml // Large screens
/res/layout-xlarge/layout.xml // Extra large screens
You can go even further and make also different layouts for portrait and landscape views by specyfing another keyword in directory's name:
/res/layout-small-land/layout.xml // Small screens, landscape view
/res/layout-small-portrait/layout.xml // Small screens, portrait view
Remember that tags order is important, so you can't write layout-portrait-small.
Use Relative layout it will solve most of your problem .Additional use Folder name with given below
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
So I used the following code below to have my application to scale screen size on different android devices but when I am testing on my Nexus 7 its does not scale and its as if it was on a 4 inch screen. When I run it in the emulator on a 7 inch screen it works. Anything wrong with my manifest file?
<supports-screens
android:resizeable="true"
android:smallScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:normalScreens="true"
android:anyDensity="true"
/>
this code goes right before the "application" part right?
Ok, so what you have to know is that support-screens doesn't make your application look 'nice' on screens you are supporting (check this link). It just tells that users with such screens will be able to download your application, but it's up to you to make it display properly. You have to create layouts for specific screens on your own.
More about it you can read in Android's documentation: http://developer.android.com/guide/practices/screens_support.html
Basically, you have to properly name your directories in which layout files are stored in order to let Android know which one should it pick up for specific device. If for example your layout's file was "layout.xml" you should have:
/res/layout/layout.xml // Default layout
/res/layout-small/layout.xml // Small screens
/res/layout-large/layout.xml // Large screens
/res/layout-xlarge/layout.xml // Extra large screens
You can go even further and make also different layouts for portrait and landscape views by specyfing another keyword in directory's name:
/res/layout-small-land/layout.xml // Small screens, landscape view
/res/layout-small-portrait/layout.xml // Small screens, portrait view
Remember that tags order is important, so you can't write layout-portrait-small.
Use Relative layout it will solve most of your problem .Additional use Folder name with given below
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
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" />
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;
}