As i new in android development i just want to know is there any way to develop Android application for different screen sizes ?
help me.
Thank you in advance
Just add this in your project.
res/values/main.xml
res/values-sw600dp/main.xml -> 7+ inches
res/values-sw720dp/main.xml -> 10+ inches
Create this folder and just copy your xml file in all the folders.
Put your main.xml in those folders:
res/values/ //your default values (in your case for phones)
res/values-large/ //specfic values for relatively big screens
res/values-xlarge/ //specific values for really big screens
large: Screens that are of similar size to a medium-density VGA
screen. The minimum layout size for a large screen is approximately
480x640 dp units. Examples are VGA and WVGA medium density screens.
xlarge: Screens that are considerably larger than the traditional
medium-density HVGA screen. The minimum layout size for an xlarge
screen is approximately 720x960 dp units. In most cases, devices with
extra large screens would be too large to carry in a pocket and would
most likely be tablet-style devices. Added in API level 9.
see more infos here: http://developer.android.com/guide/topics/resources/providing-resources.html#ResourceTypes
Google provide good article how to support multiple screens
http://developer.android.com/guide/practices/screens_support.html
General advices:
use layout - for for mobile phone layouts
use layout-sw600dp folder for 7inch tablets layouts
use layout-sw720dp folder for 10inch tablets layouts
use dimens.xml in values folder to define dimentions for your UI
you also can use
values-sw600dp and values-sw720dp with its own dimens.xml file for 7 and 10 inch tablets
Writing apps for multiple devices requires one to have good knowledge on basic concepts like : what is Dpi, Screen density , Orientation etc.
Article below is good place to start for:
Supporting Multiple Screens
http://developer.android.com/guide/practices/screens_support.html
Related
I am creating an android app and I want to be able to support as many android devices as possible that use Android 4.4 and above.
The screen sizes that I want to support are:
Normal
Large
xLarge
I have created different dimens.xml files for each size.
My first question is, the numbers that I put in each dimens.xml file should be based on the minimum dimension of each category?
For example: for normal I should design the layout in a device with dimension 470dp x 320dp, for large a device with dimensions 640dp x 480dp and for xlarge a device with dimensions 960dp x 720dp ?
My second questions is, let's say that we have our base dimension files for normal, large and xlarge, how many more dimension xml files should I create in order to support different densities too. Also do devices with Android 4.4 and above support all densities or are some excluded? (for example LDPI)
Now let's say that I exclude the LDPI density, should I make each density for each size or if I make one MDPI for each screen size and one HDPI for each screen size everything will "look" the way I want them, even in devices with XXXHDPI density?
One last thing, if you can recommend any devices to make my "base" layout that would be great.
hi you can handle size of different resolutions by this,
create different types of values folder.Create these folder inside res.
values-hdpi
values-xhdpi
values-xxhdpi
values-xxxhdpi
and dimens.xml create accordingly for different resolutions.Use all padding and margin from here.
This is way to handle different resolutions for different sizes.
for more info see the below .
for more details take a look from my project base structure
Thanks
I have read many articles on "How to make a responsive app in android" everyone has suggested to use "multiple bitmaps" for each screen. I just want to know that
(1) Can we consider different drawable folders(drawable-hdpi,drawable-xdpi,drawable-xxdpi etc) in-supporting of tablets? or just these folders are designed for smart phones in order to get responsiveness?
In Android you have 2 type of qualifiers for image sizes:
Screen pixel density (dpi): Is the screen resolution. i.e. hdpi, xhdpi, tvdpi.
Screen size: Is the phisical size of the screen. i.e. small, normal, large, xlarge.
Some tablets have big screens, but with low dpi, there so they use images from mdpi or hdpi folder. But you can create special folders for tablets using the screen size qualifier to assign images. For example you can have:
res/
drawable-mdpi/
drawable-hdpi/
drawable-xhdpi/
drawable-xxhdpi/
drawable-xlarge-mdpi/
drawable-xlarge-hdpi/
drawable-xlarge-xhdpi/
drawable-xlarge-xxhdpi/
Your tablet will use the resources from drawable-xlarge- according to the dpi resolution.
To learn more about this refer to:
https://developer.android.com/guide/topics/resources/providing-resources.html
Responsive app is not just about using different Drawables. It contains Layouts and Dimensions too.
I advise you to read these two articles from google :
Designing for Multiple Screens
Supporting Multiple Screens
I'm working on android application and got in trouble of multiple screen support. I developed the app for 1080x1920 and when i tested the app on my friends Micromax Unite 2 with resolution of 480x800, it was something else. So i made two folders in the layout as:
layout-1080x1920
layout-480x800
thinking that the 480x800 device will pick up the layout-480x800 folder. But no it used the layout-1080x1920. So what should i do? So that the device having resolution of 480x800 works on layout-480x800
I suggest naming the folders as such:
layout-sw600dp
Where sw600dp means Screen Width 600dp. This layout folder will be used by devices with screen widths of 600dp or more (typically all 7-10 inch tablets, or just very dense screen). And when you are targeting for the phone use just the layout folder without any specified criteria. All phones not matching the sw600dp will use the default layout resources. Possibly also consider using
layout-sw600dp-port
if you need to use specific layouts for portrait orientation, likewise you can do
layout-sw600dp-land
if you wanted to specified layouts for landscape.
The link cricket_007 provided is where I learned this information
Note that 1080x1920 equates to about 540 x 960 dp in dp measurement, which is why I suggested to use the particular 600dp for width
giving the folder names pixel according to android screen support dev page. Even if you know all possible resolutions for every device, the android system takes those *xml files/drawables etc specified by their DPI, not PX. Those dpi resolutions still can change on runtime, such as, when your activity uses a tool bar (which is not part of your dpi resolution). Name your folders layout-xlarge, layout-large, layout-normal, layout-small for *xml layouts. I suggest to put 4 different xml files with same name in each of them and try it again for different devices.
I know that for supporting different screen size we use layout,layout-large,layout-xlarge folder , but i have confusion regarding drawable folder,by default they are ,
1. drawable-ldpi For low density screens
2. drawable-mdpi For medium density screens
3. drawable-hdpi For high resolution screens
4. drawable-xhdpi For extra high resolution screens
But A simple approch is
1.Drawable
2.Drawable-large
3.Drawable-xlarge
is it ok to go with this approch?
Google changed layout system after API 13 (Android 3) so both of them works but it's recommended to use dpi system which related to screen density but old system was realted to screen sizes which might make problems with large screen devices with low dpi screen density
It is better to use screen density folders because (quoting the Android doc)
Maintaining density independence is important because, without it, a UI element
(such as a button) appears physically larger on a low density screen and smaller
on a high density screen. Such density-related size changes can cause problems in
your application layout and usability.
So using density-pixels Android scales your widgets (Buttons, ImageViews, etc) by itself relating your Activity and the Drawables you need to the appropiate res folder. In fact, you should be using this density system in your Layouts too (layout-mdpi, layout-hdpi, etc).
I'm really feeling confused. From the docs at developer.android.com, it seems in order to keep my images scaled correctly (aspect ratio too) across all current Android devices I need all these layouts below. Is that really what everyone is doing? Am I missing something, or should I be going about this a different way?
Low density Small screens QVGA 240x320
------------------------------------------------
layout-small-ldpi
layout-small-land-ldpi
Low density Normal screens WVGA400 240x400 (x432)
------------------------------------------------
layout-ldpi
layout-land-ldpi
Medium density Normal screens HVGA 320x480
------------------------------------------------
layout-mdpi
layout-land-mdpi
Medium density Large screens HVGA 320x480
------------------------------------------------
layout-large-mdpi
layout-large-land-mdpi
High density Normal screens WVGA800 480x800 (x854)
------------------------------------------------
layout-hdpi
layout-land-hdpi
Xoom (medium density large but 1280x800 res)
------------------------------------------------
layout-xlarge
layout-xlarge-land
Your app will work on 100% of the devices with the classic layout.
You can just add some buttons or change the layout in landscape mode by adding some qualifiers but that's up to you!
For instance, on LDPI (small resolution) device, you may want to adjust some buttons or change a little bit to fit the small screen.
You may also want to put some buttons on the right in landscape mode and in the bottom of your layout in portrait!
You do not "have to" use them.
According to Android Dev Protip from Roman Nurik about screen size qualifiers:
If you have custom layouts for larger screen devices such as tablets,
now's the time to stop using the -large or -xlarge resource qualifier
and switch to using -swXXdp or -wXXdp qualifiers. The latter were
introduced in API level 13, which basically all tablets now have
support for according to the latest platform version charts1.
means that for basically all cases where -large would have any effect,
-swXXdp can be used instead to provide more granularity.
So which actual sw or w qualifiers should you use? Here's a quick
just-give-me-something starting point:
7" tablets: Instead of layout-large, use layout-sw600dp.
Example: Nexus 7 = 960×600 dp; the smaller of the two dimensions is
600.
10" tablets: Instead of layout-xlarge, use layout-sw720dp.
Example: Nexus 10 = 1280×800 dp; the smaller of the two dimensions is
800. Some 10" tablets are a bit more narrow so 720 is a commonly used switching point.
There's more to it than just that (you really want to choose switching
points based on your content's minimum requirements, not on device
form factor), but that's a #Protip for another day (::cough:: +Nick
Butcher ::cough::).
In the layout if you do not use AbsoluteLayout, you application is going to be resized to fit the screen.
But in some cases, for smaller screens you need declare a new layout with less components for example.
For images:
You has some options.
Simple ignore some resolutions and let the device choose the best image to it.
Declare on AndroidManifest for wich sizes you want to support.
Or has just one and let the resize screw your application.
Yes. You should define different layout for different screen resolution.
When you are supposed to work with tablet kind of application. That time really you feel that. There is a need of different layout. Because Tablets always comes in different size.
One more thing, When you are working on android, means you should always taste your app with real device. And also test with different size emulators.