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
Related
When I create small,normal,large,xlarge layouts:How Android Detects Screen Size phone for use this layouts?base on dp or dpi or px?
Is the result always right?Because some devices are smaller in physical size but the density is higher so if based on density this detect is not always correct.
Am I right?
Android uses dp, but there are a lot of variants you can create in your resources for example
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)
You can cover more resolutions using different configs, but I think is hard work to cover everything, because how I said we have different resolutions, screen sizes and now we have notch.
res/layout-560dpi/
res/layout-ldpi/ ...
Bellow, I copy a link about this
https://developer.android.com/training/multiscreen/screensizes
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
This is how my layout looks on the phone (landscape):
button wrapper (marginTop 10dp, margin left 5dp and 3 dp between buttons)
The problem is when I run the same layout on the tablet:
As you can see there is an extra space below the button wrapper.
Am I need to create different layout for each device display?
Yes you should create another layout for tablets. if the layout for the phone comes in tabs obviosly it will get smaller..youcan go through this oink about creating different layouts for different displays..Mainly for layouts will be provided for an app
layout-small ,
layout ,
layout-large ,
layout-xlarge,
Link
Iam not getting what your actual point is..but yes for tablets you need to make different xml layout files which are put under layout-large and layout-xlarge(depending upon your requirement) folders. And if you'r not doing so then your tablet will render the layout from your default layout folder.
Is this what you were asking ?
You can do with help of this
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 landscapeorientation
for drawable
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
I think you need this
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/practices/screens_support.html
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;
}
I saw one android app my galaxy tab(1024*600), it has fixed resolution 800*480.
How to fix my app's resolution like 800*480?
my client wants to fix app resolution..
You can explicitly define your layout width and height in layout xmls to be 800*480 for all the un-supported resolutions like 1024x600.
A list of sample layout folders:
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
In case of 3.2 or later, you can define layout files for tablets as well:
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 don't recommend fix your width and height to a specific value but since it's client request, I guess you have to take it.
Or you could set target sdk version to 1.5 or 1.6. I haven't really tried it yet, but I read somewhere that doing so limits the application to be displayed in a lower resolution.