I have a Micromax AQ5000 with Screen Resolution- 1280*720 pixels and Motorola Moto G XT1033 with resolution 720 x 1280 pixels.I have a layout folder named layout-sw360dp which I designed for devices like Samsung s4,s3,Micromax canvas etc but this Motorola device is also using the same layout and this creates the images displayed as distorted in it.
How can I create a folder for the small device(Moto g) I tried layout-xhdpi but it doesn't work how can I name layout with height and width.
Well you are right in some sense android should take layout dependent on different densities but some mobile do not fall under specific density. Therefore android will pick up default layout from layout directory.
to support multiple screen resolution provide different layout for different screen sizes, you can make following directories in res directory like this
layout-hdpi
layout-mdpi
layout-xhdpi
layout-xxhdpi
layout-w320dp-h408dp
layout-w480dp-h800dp
layout-w480dp-h854dp
layout-w720dp-h1280dp
layout-w1080dp-h1920dp
when you provide layout in all this directories you will give multiple screen support for different sizes as well
layout-w1440dp-h2560dp
Use "dip" instead they will help you in debugging your layout as they will try to keep a coherent size to multiple screen resolutions,
<ImageView
android:id="#+id/avtar_animation_11"
android:layout_width="45dip"
android:layout_height="45dip"
android:src="#drawable/avtar011"/>
while supporting multiple screen when you give "dp" to dimensions, Actually android expects you to provide different values for different screen resolution. Lets say below is your imagview dimensions make few folders in res folder in your android project like these below
values-hdpi, values-mdpi, values-ldpi, values-xhdpi, values-xxhdpi
and in them make a dimens.xml file each of them and write
<dimen name="image_view_width">28dp</dimen>
<dimen name="image_view_height">28dp</dimen>
now that i have mentioned "dp" here instead of dip android wants me to keep track for different dimensions for different screen resolution, So i will change the image_view_width and image_view_height values are in separate values folders where dimens.xml is located. Make sure your dp values change as per your screen resolution you want your view to fit in.
<ImageView
android:id="#+id/avtar_animation_11"
android:layout_width="#dimen/image_view_width"
android:layout_height="#dimen/image_view_height"
android:src="#drawable/avtar011"/>
hard part is over now android will pick one of dimens.xml values depending on which screen your app is running, Voila now your layout rocks
Related
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'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 have an Android application with one layout file. I have different layout files for different densities, i.e., layout-hdpi, layout-mdpi, etc. I also have different dimens files in corresponding value directories (values-mdpi, values-hdpi, etc).
My problem is that I would like to use different layouts for 4 and 5 inch screen devices. I am testing on two physical a 4 inch and a 5 inch and both devices use the layout from the /res/layout folder and the dimens file from the /res/values-hdpi/ folder (in other words, they use the same resources).
Is there a way to make the 4 inch device use a different dimens.xml file - if not automatically, can this be done programmatically?
You can use something like layout-sw320dp or similar. This will differentiate layouts based on minimum display width.
Here is much more about it:
https://developer.android.com/guide/practices/screens_support.html#NewQualifiers
Density is not related to size, they tell you how many pixels there are in on square inch of screen, not how may inches of space there are in the screen. you should use size related resources. for example layout-w500dp folder would be used for screens that have at least 500dp of width.this should help
I have 3 devices
1) galaxy nexus 720*1280 (xhdpi, normal size category )
2) motorola 480*854 (hdpi, normal size category)
3) htc 320*480 (mdpi, normal size category)
I have my xmls in my layout folder. In my xmls I need to fix sizes to my textviews,Edittext(it will expand with the text entering).
Because of this,I am getting problems in my motorolo,htc devices.I cannot able to prepare different layouts because these 3 devices are comes under layout-normal(layout).
I have Textviews in Rectangular background,with the text increases rect box is getting expanded.
Is there any option to prepare different layouts for each of the devices.
please suggest
Thanks
You can target densities by using a layout folder like layout-mdpi, layout-hdpi and a layout-xhdpi. Why would you want to do this? using dips for everything will be fine.
Edit: suggestions based on the comments you gave:
by using a value like 200dp, the boxes on all devices kinda have the same size. Not in pixels but in actual size on the screen. This is what dips (the dp unit) is made for.
The screens are supposed to look kinda the same on the different device sizes. Read the description on http://developer.android.com/guide/practices/screens_support.html especially the section named "Density independence".
After reading that and if you still really, and I strongly suggest you don't do that, want them to look different on different screen sizes do this.
In your layout xml define the width as android:layout_width="#dimen/the_width"
In the folder values, create a file values.xml. In there define a dimension like this <dimen name="the_width">200dp</dimen>. 200dp is an example and will be the default value.
Override this value in the values-hdpi, values-xhdpi and/or values-mdpi folder, by creating the same values.xml, but with a different value for the_width.
This will make the edittext have a different size on different screen sizes.
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.