different layout parameters for different devices - android

I have created a layout in my xml file and have a LinearLayout that is displayed at the top of the activity. I have set its width to fill_parent and its height to 54dp. The height of the layout looks good on devices with bigger screens like Samsung Galaxy, but on smaller devices it looks too big. Is there anyway that the layout will have different height on different screen sizes? I am guessing that this might be achieved by dp, dip, etc. but I'm not sure as to what exactly they do

make layout-normal-hdpi, layout-normal-mdpi and layout-normal-xhdpi folders and copy the same xml in all the three folders than set the different height on each xml as per the devices. This is the standard technique which is been followed. Try this you will surely get desired result.

Hope this will help you...
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
Low density Small screens QVGA 240x320
res/layout-small-ldpi
res/layout-small-land-ldpi
Low density Normal screens WVGA400 240x400 (x432)
res/layout-ldpi
res/layout-land-ldpi
Medium density Normal screens HVGA 320x480
res/layout-mdpi
res/layout-land-mdpi
Medium density Large screens HVGA 320x480
res/layout-large-mdpi
res/layout-large-land-mdpi
High density Normal screens WVGA800 480x800 (x854)
res/layout-hdpi
res/layout-land-hdpi
Xoom (medium density large but 1280x800 res)
res/layout-xlarge
res/layout-xlarge-land
Comment me for any query...

Related

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)

how to i develop android application to work in different screen resolutions

I,m working on android project.
Actually i have develop on small app in honeycomb with resolution(1024*600), when am running the same app in different resolution let say android 2.2(froyo) screen the alignment of images in app screen changes.
Note:Images that are place in xml file are manual arranged(no wrapper thing used for width and height)
Please help me out this question asap..
regards,
Murali...G
Mainly we need to look up is the usage of UI patterns like action bar, Dashboard etc.
But the key point is you should use less static images and as you also use tablet. You should've used Fragments(Of course you would ve done. In case if you have done. Please do it).
Also use 9 patch images or colors for backgrounds. If you are using different images then. You need to keep images for different density.
Maybe all I say is abstract as this question is a abstract one. There is no one line answer for this. As this is a process by itself.
//design your xml in this way
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
Low density Small screens QVGA 240x320
res/layout-small-ldpi
res/layout-small-land-ldpi
Low density Normal screens WVGA400 240x400 (x432)
res/layout-ldpi
res/layout-land-ldpi
Medium density Normal screens HVGA 320x480
res/layout-mdpi
res/layout-land-mdpi
Medium density Large screens HVGA 320x480
res/layout-large-mdpi
res/layout-large-land-mdpi
High density Normal screens WVGA800 480x800 (x854)
res/layout-hdpi
res/layout-land-hdpi
Xoom (medium density large but 1280x800 res)
Check this Android class:
http://developer.android.com/training/multiscreen/index.html

layout-large-land-hdpi error

I'm trying to use inside res the folder
layout-large-land-hdpi
but the sdk gives me an error and does not compile.
layout-large-hdpi works!
As it says here, it should work!
//yes we can use either layou-large and layout-large-mdi and so..
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
Low density Small screens QVGA 240x320
res/layout-small-ldpi
res/layout-small-land-ldpi
Low density Normal screens WVGA400 240x400 (x432)
res/layout-ldpi
res/layout-land-ldpi
Medium density Normal screens HVGA 320x480
res/layout-mdpi
res/layout-land-mdpi
Medium density Large screens HVGA 320x480
res/layout-large-mdpi
res/layout-large-land-mdpi
High density Normal screens WVGA800 480x800 (x854)
res/layout-hdpi
res/layout-land-hdpi
Xoom (medium density large but 1280x800 res)
res/layout-xlarge
res/layout-xlarge-land

Android screen resolutions

I am following this tutorial link
There three types of screens
xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp
But there are three folders
drawabale-hdpi
drawabale-mdpi
drawabale-ldpi
I placed images of xlarge in hdpi
that of large in mdpi
and that of normal in ldpi
but where to place the images of small screens?
Sorry for bad english
For example, 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
and Screen Sizes.
I hope this help.
hdpi, mdpi and ldpi refer to the screen density in dots-per-inch. This is completely separate from the screen size (small, large, etc).
You can have large screen with low density, or a small screen with high density, etc.
You can cater for different screen sizes by putting different layout resources in res/layout-small, res/layout-large, etc.
These are two different things - hdpi/mdpi/ldpi are screen densities (i.e., how many pixels per square centimeter) while xlarge/large/normal/small are screen sizes (the physical dimensions of the screen). So the small screen images would go in drawable-small, normal in drawable-normal, etc.
There's a lot more info about this stuff on the Android developer website.
Screen size has no relation with density. xlarge screen does not mean it has hdpi density. For example tab like galaxy 10.1 pr motorola xoom has xlarge screen but mdpi density so for them you make a separate folder drawable-xlarge. and for this you have to add android:xlargeScreens="true" in manifest.
And devices like galaxy s2 or htc desire has hdpi density. Devices with small screens like galaxy pop are mostly have ldpi density, normal screens like galaxy ace are mostly mdpi devices and devices with large screens like galaxy s2 are mostly hdpi devices, and some devices like tab P1000 have large screens but mdpi density and for them you have to make folder drawable-large-mdpi.

Android Scale Problem

I have made the relative layout and I used fill-parent , wrap-content and for some margin I have to use "dp".
But When I check on different devices the scale/density change So on surfing from Android Developer site I found that I have to defined layouts like
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
So is there any easy or smart trick for density problem without define these layouts... and work wll on all devices with only one standard layout
You don't need those different layout folders for density problems. You need those layouts for defining different looks for different screen sizes. If you want to use different images for different densities, you need add images with different resolution to the drawable-xhdpi, drawable-hdpi, drawable-mdpi and drawable-ldpi folders.
Android automatically selects images from right folder depending on screen density.
drawable-xhdpi - density higher than 240
drawable-hdpi - density 240
drawable-mdpi - density 160
drawable-ldpi - density 120
Start your designing process always for medium density screens.

Categories

Resources