I have a two circles in a background image and I want to put two buttons in them. I am using relative layout. I have created several layout folders and images using guideline (layout, layout-large etc). But still the buttons are somewhat up or down in different actual devices. I am assuming this is because of Android default screen density bucket. Because if I provide only one layout for 320 to 479 dpi screen, It is possible that there could be a lot of devices in between. And my only layout for this range is surely going to be distorted? How do you design for supporting multiple devices? Thanks for you help in advance!
Add all the listed dimens.xml in vlaues folder for your project and manage them accordingly
values-sw320dp
values-sw360dp
values-sw480dp
values-sw600dp
values-sw720dp
This will definitely solve your problem of
supporting multiple devices.
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.
We have a confusion about the best practices of Android layout design. Up to now we designed layouts either for each screen sizes (hdpi, XHDPI, xxhdpi.... ) or for width/height concept (sw, sh etc folder structure). Any away we had multiple layout to support multiple screen sizes. Sometimes most of they are just a copy of hdpi as Android managed to scale things properly.
Now we hired a senior Android developer with 5. 5 Years of experience and he prefers to write only one layout to all screen sizes. He argues that this is the latest way. He only write one layout and when it comes to images he add them to different drawable folders (hdpi drawable folder etc) with different sizes to match across all screens
At the moment I am also confused thinking whether I really missed an industry standard, because this new guy's past UIs also seems pretty good.
Any advice on this please?
Up to now we designed layouts either for each screen sizes (hdpi, XHDPI, xxhdpi.... )
Those are not sizes. Those are densities.
or for width/height concept (sw, sh etc folder structure)
Those are sizes.
He only write one layout and when it comes to images he add them to drawable folders (hdpi drawable folder etc) with different sizes to match across all screens... whether I really missed an industry standard
Having layouts based upon densities has been a code smell since late 2009, when the concept of screen densities was introduced. Having drawables based upon densities has been a best practice over the same timeframe.
In terms of the "one layout" portion, that may not be practical in all cases:
Different orientations (portrait vs. landscape) may require different layouts (e.g., to get forms to fit without scrolling)
Substantially different screen sizes (e.g., phones versus tablets) may require different layouts
Substantially different UI approaches (e.g., watches vs. handheld mobile devices vs. TVs) usually require different layouts
you should fix your height and width of the view in dimension file for various resolution example:
values folder:
90dp
75dp
values-hdpi folder:
<dimen name="width">100dp</dimen>
<dimen name="height">85dp</dimen>
like this do for mdpi,,xhdpi,xxhdpi and put this in your view.
android:layout_width="#dimen/width"
android:layout_height="#dimen/height"
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 am making android application in tablet using fragments so that I arranged 8 buttons vertically in 10.1 tablet it is showing fine but in 7.1 tablet only 5 icons it is showing.
So How can I manage height and width properly in all tablets ... please help
Remember to write different xml layouts (with same name) and place to different folders: layout-large, layout-normal, layout-small and layout-xlarge. Same is with drawables (different size images) and values (different type padding and other values). These folders are for different phone/tablet types with various resolution and screen size. If you do it, then you can easily manage layout for small device and not touch big screen devices. Device is picking xml file automatically so it's good practice to place xml files in different folders for various phones.
More information you can find in http://developer.android.com/guide/practices/screens_support.html
You can use different layout for different screen sizes. You can also add different buttons and other drawable also. Please see the link
Supporting Multiple Screens
You can write different xml layouts using different folders:
For example:
res/layout
res/layout-sw600dp //used by 7''
res/layout-sw720dp //used by 10''
Also you can use the same layout with the same component but with different dimensions.
You can use #dimen/my_dimen notation, and then put your my_dimen in different folders like:
res/values/dimens.xml
res/values-sw600dp/dimens.xml
and so on..
Official doc: http://developer.android.com/guide/practices/screens_support.html