In my android app, I want to support multiple screen sizes. I realize that for Android "large" means a lot of the current phone screens at 480 x 800 pixels as well as a 7" tablet like the Nexus 7 which has 800 x 1280 pixels. But I'd like to create 2 separate layouts for those two display sizes. I've found that rather than using res/layout-large, using res/layout-h800dp gives me greater control of which size screen uses what layout. (I'm using a portrait orientation, hence h800dp) The problem I'm having is this: sometimes the h800dp layout uses the images in the drawable-mdpi folder, and sometimes it uses the images in the drawable-hdpi folder. I'm using the same syntax in the xml to call the images: `android:src="#drawable/image", but in one activity it looks in the mdpi drawable folder, and in the next activity, it looks in the ldpi drawable folder. Is there any way to get the h800dp layouts to always look in the ldpi folder?
This link explains nearly everything regarding screen properties (DPI, physical size, resolution, etc.)
What you may be able to do is specify folders like layout-large-hdpi, layout-large-mdpi, and layout-large-ldpi.
Experiment with blending these types together in folder names.
Related
hi I'm new in android developing and it's my first app.
I have made these folders in address : app\src\main\res for supporting multiple phone and tablet screens and put proper dimens.xml files in them.
values-ldpi
values-mdpi
values-hdpi
values-xhdpi
values-xxhdpi
values-xxxhdpi
values-sw600dp
values-sw768dp
values-sw800dp
first of all, are they complete or am I missing some screen sizes?
second, I've tested the app on several devices and it's working fine and has proper user interface in all phones but on the Galaxy Grand Prime which has a 5 inch 540 x 960 pixels display that means 220 dpi. this phone using hdpi dimens but UI is a bit messy.
The following pictures may make my point better :
Proper UI , as it is shown in other devices
VS
UI in galaxy grand prime 220 dpi display
as UI is completely OK in other devices, I thought I should make a specific dimens.xml file for that kind of dpi, so I made values-sw220dp. but after that other phones used this dimens instead of hdpi dimens and problem got worse because UI was fine in the galaxy phone and was not proper in other hdpi displays. and now I don't know what should I do.
can anyone help me in this issue?
at last sorry because of flaws in my english , as you can guess I'm not a native.
are they complete or i'm missing some screen sizes?
If you read the guides which I mentioned at the end of my answer you will find that there are very many possibilities of defining resources folders. I think nobody will want to implement all of them.
Usually you look at your app and then decide on maybe three or four screen sizes you want to support. I think "sw220dp" is important, if only to show a message that your app needs more space :-).
So there could well be three to five layout folders (sw220dp, sw320dp, maybe sw480dp, sw600dp, maybe sw820dp). If you need orientation-dependent layouts, then the number will be twice that much. (Why ? That's explained very well in the guides linked below)
You already know that there are different types of resources. Some of them do not depend on the screen resolution (e.g. layout files), some do (drawable resources).
So first of all you decide which screen sizes you want to support. Let's say they are "phone", "tablet" and "220dp". You create three layout files by the same name "my_activity.xml" and put them in three folders
for the really small window: res/layout-sw220dp
for the mobile phone: res/layout-sw320dp
for the tablet: res/layout-sw600dp
By the way, "sw" stands for smallest width which is the minimum length of the screen, no matter what the orientation is currently.
Now let's assume you have created three different layout files and all of them contain an ImageView like this:
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="#drawable/my_picture" />
This is where the screen resolution comes into play: 24dp is a size value in "density-independent pixels". It will be resolved depending on the screen resolution of the device. So you need different versions of my_picture.png, and for this you need different folders for drawables. They are named after the different categories for screen resolution so the runtime knows which png file to pick:
res/drawable/ldpi (although I read somewhere you can skip that because the pictures will be scaled down from hdpi nicely)
res/drawable (here go the resources for res/drawable-mdpi as well as every drawable resource for which resolution does not matter, e.g. drawables defined via xml files)
res/drawable-hdpi
res/drawable-xhdpi
res/drawable-xxhdpi
res/drawable-xxxhdpi
Helpful links:
Providing Resources
Supporting Multiple Screens
This is my first time working with multiple screens. I want to build my application for multiple screens i.e from sw320dp to sw720dp. I have created the following layout folders.
res/layout-sw320dp
res/layout-sw360dp
res/layout-sw480dp
res/layout-sw600dp
res/layout-sw720dp
I have copied all the xml files inside these folders. Is there anything else I need to add to make sure all the layouts support multiple screens. I have gone through the android documentation but I am not clear with the manifest.xml part. If anyone implemented multiple screen support in their application, so please do provide a description and implementation of the same.
Step 1 -You have to create different values folder for Different values for different screens.
Go to Your Project / app / src / main / res.
Right click on res and create different values folder in it.
Step - 2. Create folders named
values-large
values-small
values-sw320dp
values-sw320dp-hdpi
values-sw320dp-xhdpi
values-sw320dp-xxhdpi
values-sw480dp
values-sw600dp
values-sw720dp
Step - 3. Create dimensions.xml file in values folders.
Different values for different screen size.
values-ldpi 2.7" 240*320 ldpi
values-ldpi 3.3" 240*400 ldpi
values-ldpi 3.4" 240*432 ldpi
values-mdpi 3.2" 320*480 mdpi
values-hdpi 4.0" 480*800 hdpi
values-hdpi 3.7" 480*854 hdpi
values-xhdpi 4.7" 1280*720 xhdpi
values-xhdpi 4.65" 720*1280 xhdpi
values-sw480dp 5.1" 480*800 mdpi
values-sw480dp 5.4" 480*854 mdpi
values-sw600dp 7.0" tablet 1024*600 mdpi
values-sw720dp 10.1" tablet 1280*800 mdpi
when you attach dimension.xml file with your layout than you will get direct effect with your screen size.
This will help you to set dimensions for all type of screens.
There is a difference between supporting multiple screen sizes and creating different layout.xml files for each screen size.
In all the apps I've ever worked on, there were really only three different kinds of screens we cared about: small phones (years-old devices that our users weren't upgrading), "regular" phones (e.g. modern-day Samsung or LG phones etc), and tablets. Even considering those three kinds of screens, we often didn't need to create more than a single layout.xml file for a single screen.
If you have just one layout.xml file, it will display itself on any screen size. To "support" multiple screen sizes, you just need to make sure that your content looks good on short phones and tall phones, on wide phones and narrow phones, on phones and tablets, etc. This generally comes down to using dimensions like match_parent, or layout_weight to fill available space, etc.
It is only when you actually need to change what elements are on screen (as opposed to how big elements are) that you need to create extra layout.xml files. For instance, perhaps you know that a certain set of text + images just won't fit on smaller phones. Then you can create one res/layout/layout.xml that has only the text, and another res/layout-sw360dp/layout.xml that has the text + the image. Or maybe you have some content that you want to display side-by-side on a tablet, but you only want part of it on phones. Then you can make one res/layout/layout.xml with the normal content and one res/layout-sw600dp/layout.xml with the tablet-only content.
Regardless, when you decide that you do want to make multiple versions of a layout for different screen sizes, the only thing you have to do is create copies of your layout.xml in different layout-swXXXdp folders. Don't bother with layout-large unless your app supports really old API levels; the swXXXdp method is much more accurate and solves the same problem (but was only added in API 13).
Hey you dont need to do anything in manifest.
You have done the part with layouts.
Next you can do is to add support in drawable folder i.e. different density images for different sizes.
And if different screens require different values(dimentions etc) you need to create multiple file in values.
I am having trouble managing my application layouts in three different resolutions; 720x1280, 1080x1920 and 1440x2560.
In drawable-xhdpi folder is the corresponding images to 720x1280 resolution.
The folder drawable-xxhdpi is the corresponding images to 1080x1920 resolution and in drawable-xxxhdpi to 1440x2560.
I began to adjust the screens in layout folders. The layout-sw360dp was setting screens for 720x1280 and the layout-sw480dp the 1080x1920.
When testing in the emulator 720x1280 all settings worked perfectly.
But to test the emulator 1080x1920, oddly taking this information in layout-sw360dp folder and not the layout-sw480dp.
In the case of adjusting each folder layout-sw360dp and layout-sw480dp, I'm using margin with values in 'dp' and emulator higher values (layout-sw480dp) are being dropped are being used and the values of the layout-sw360dp.
How can I manage three screen sizes correctly?
Well designed Android applications cater for varying screen sizes, the screen size being a function of both resolution and density. Using several layout-sw###dp folders allows you to vary the layout according to the width of the display, e.g. showing fewer elements and controls on a small screen and perhaps more detail on a large one.
The 'sw' in the layout folder name is the 'shortest width' a display must have in device independent pixels (dip). One dip = 1 real pixel on a 160 density screen. So on a 320 density screen, 2 real pixels make up one dip.
Your nexus 5 has 480/160 = 3 real pixels per dip. So with a width resolution of 1080, that is 360dip wide.
Your nexus 4 has 320/160 = 2 real pixels per dip. So with a width resolution of 768, that is 384dip wide.
Neither device is more than 480 dip wide so both use the sw360dp folder.
Both devices are physically very similar in size. The Nexus 5 (5.4inch screen) has more pixels than the Nexus 4 (4.7inch screen) but the pixels are physically smaller. So it is correct that the same layout is used for both. The UI should look the same on both devices, assuming you correctly specify the size and layout of your various UI elements in dip.
As a further example, I have an old tablet (10inch screen) with a resolution of 800x1280 and a low density of 149, hence is 859dip wide. You can comfortably display far more info on a screen that size than on a Nexus 4/5, hence you might consider creating a layout-sw720dp for that.
So you appear to be doing exactly the right thing already by designing different layouts for different screen sizes. Just remember that resolution is not the same thing as screen size. Screen size is a combination of resolution and density.
As for your drawables, you are also already doing the right thing by using drawable-xhdpi, drawable-xxhdpi etc with appropriate resolution images in each one. So for example a small device with an extremely high density would likely use the 1440x2560 images and the sw360dp layout. My low res tablet would use the 720x1280 images, unless you'd put something in drawable-mdpi which is where it would look first.
So firstly you'd create appropriate resolution images in the drawable folders so that they would look as good as possible on different resolution screens. Then create appropriate swxxxdp for your layouts so they take up the appropriate space depending on the physical screen size, i.e. make good use of available screen space on large devices and don't clutter up small ones. It's likely you would want to go further and create -land and -port versions of each as well.
It is worth noting that even if you only have one layout folder and one drawable folder, your application will still work on all devices. Android simply looks for the best choice and if there is only one, it'll use that. Adding in the various folders simply allows you to make your app look as good as possible on a range of devices.
Everything I have discussed here and more is explained in detail at http://developer.android.com/guide/practices/screens_support.html.
can I change layout dpi that use my application on device?
(on developed application that works fine but on small screen size devices everything looks big )
You'll want to supply resources for all the screen size buckets:
/drawable/ (default images)
/drawable-ldpi/ (small dpi screens)
/drawable-mdpi/ (medium dpi screens)
/drawable-hldpi/ (large dpi screens)
/drawable-xhdpi/ (xtra large dpi screens)
See here for help: http://developer.android.com/guide/practices/screens_support.html
and here for a list of devices using which DPI bucket: http://blog.blundell-apps.com/list-of-android-devices-with-pixel-density-buckets/
small screen size devices everything looks big .
Read this Supporting Different Device
Its an layout issue ,Try to use relative layout and linear layout for placing the objects in xml.And for images use .png extension and use nine patch images ,so that it fits in all screen,this will support most of the screens
You need make images for all DPI screen so that it is supported by all types of devices.
Android automatically sets these images for your application according to your device DPI.
Please be sure of all of your resources and see link. It will help you more.
I am stuck in a situation.
I created an application for Samsung Galaxy Tab 7". The same application when i run on the HTC Flyer it shows very small fonts.
I tried following :
I thought may be the screen of HTC Flyer is xhdmi so i crated folders accordingly
res -> values-large-xhdmi -> styles.xml -> <item textsize>20</item>
res -> values-large-> styles.xml -> <item textsize>16</item>
this is not working.. :(
any help will be highly appreciable in this regard.
Thanks.
Check out this recent blog post on sizes: http://android-developers.blogspot.com/2011/07/new-tools-for-managing-screen-sizes.html
A typical 7” tablet has a 1024x600 mdpi screen. This also counts as a
large screen.
The original Samsung Galaxy Tab is an interesting case. Physically it
is a 1024x600 7” screen and thus classified as “large”. However the
device configures its screen as hdpi, which means after applying the
appropriate ⅔ scaling factor the actual space on the screen is 682dp x
400dp. This actually moves it out of the “large” bucket and into a
“normal” screen size. The Tab actually reports that it is “large”;
this was a mistake in the framework’s computation of the size for that
device that we made. Today no devices should ship like this.
So you need to think of the Galaxy as a large sized screen but with hdpi.
THe HTC Flyer will be large sized screen but with mdpi.
When specifying sizes you need to stick with dp, as this normalizes all sizes to scale appropriately for the different density screens. Use a dimension to specify in a xml value resource.
As milind hinted (i think), it is probably better to use the same style for these two screen sizes and specify a dimen resource. This resource can then be customized for the different displays.
The bottom line, however, is that you are using text size differences based on the screen size. The text size should be indicated in dp, so it will scale accordingly to any screen density. Really, the only resources that should be based on screen size are layouts.
If you are plan to make Multiple resolution Supporting android application just you have care about image and xml no other needs that you have same images with three different size putting in different folders like drawable-hdpi, drawable-ldpi, drawable-mdpi. you can make style.xml common for all.
Thanks