Android - common techniques for scaling screen layouts - android

I realise this topic has been covered to death, and I have read the official and unofficial developer guides on it so know the theory. But I'm still unsure which path to take to ensure my app looks good on multiple screen sizes. My app is a simple navigation style app which is designed to be portrait only. At this stage I'm not interested in making different designs for landscape or multi-pane screens for tablets etc. I just want each screen to be scaled up/down so it looks in proportion with the screen size it is being displayed on - i.e. text and images are sized up/down as appropriate. I designed the app for a classic 480x800 hdpi device which it looks great on, I just want to make it look in proportion for the Galaxy S3/Nexus 7 etc. I'm already following these guidelines :
Using RelativeLayouts
Using DP units for padding/margins
Using SP units for fonts
Using 9-patch images for buttons
However I'm finding it still looks small and a bit lost in the middle of the screen on the larger devices. In particular, my main menu screen is a grid of 6 image buttons which I can't get to scale well. I don't want to have multiple copies to maintain of the same screen (normal/large/xlarge), just want one layout. I was considering the following :
Using value-normal/value-large etc. folders to store XML files with DP/SP values for sizes of images/text
Changing RelativeLayouts to LinearLayouts with weights (although I initially struggled with LinearLayouts and changed to RelativeLayouts
Are either of these valid approaches, or is there a better approach?

Personally, I would go with the first option. While this will work well for phones, it will make the layout seem somewhat bloated on tablets. Hence, another approach would be to create separate layouts for tablets and place them in the layout-large and layout-xlarge folders for 7" and 10" tablets respectively.

Related

Combining screen height with different resolution layout files?

I set up my Android application to support different screen resolutions (ldpi, mdpi, hdpi, xhdpi, ...) and that seems to be working as it should. Different screen heights on the other hand are not scaling correctly: I optimized my design to fit on the small screens (of the default Android Studio emulators) which means that there is a lot of empty space on longer devices. Is there any way to combine screen resolutions (xhdpi, ...) with screen lenght (long, ...)? If this is not possible at all I would really appreciate alternative methods of layout scaling in order to fix my problem. I currently use dp and RelativeLayouts only.
Thanks in advance.
RL in the picture below represents RelativeLayouts.
I would suggest using multiple nested linear layouts while specifying layout weights to scale components on all kinds of displays (see this guide for example). Tip: You can use empty views to create dynamic spaces.
Also in some cases it is useful to specify portrait and landscape layouts separately (see this guide) although then you have to manage some duplicate code.

Is it necessary to create "small, normal, large and xlarge android xml layouts" folders if i want my application to run of all Android devices

I am developing an Android Application that supports all kind of Android devices like mobiles and tablets. But it's time consuming to create multiple folders (small, normal, large and xlarge android xml layouts) to support all the Android devices. Is there any way to build an android app that runs on all android devices without creating these folders:small, normal, large, xlarge etc?
You only need to create unique layouts (ie. *layout_mdpi* ) if you want something unique for that particular screen size.
If you want to use the same layout on all different screen sizes, you will only need to create a single layout (in the layout folder).
Only if you want to customize a particular layout would you need a new FOLDER in layouts (named: layout_mdpi) in that folder you would have multiple copies of customized layout with same name (ex. my_layout.xml)
To clearly answer your question - you will only need the layout folder and no other ones in your casel
Ex.
res\layout\my_layout.xml // this folder is all you need if this layout will work on all screen sizes
res\layout_mdpi\my_layout.xml // you ONLY need this if you are presenting something unique on this screen size.
In Android we need to maintain different folders for the layouts with different resolution reason behind it is the use or the resolution of the Android Device on which the application gonna execute.
small Resources for small size screens.
normal Resources for normal size screens. (This is the baseline size.)
large Resources for large size screens.
xlarge Resources for extra large size screens.
Android OS select the specific layout it self by checking the compatible device and its resolution.
So, better to create folders to support in multiple screens
For More Info refer this
Is there any way to build an android app that runs on all android devices without creating these folders:small, normal, large, xlarge etc
Consider this, you have a button (with match_parent) that stretches full width of a screen in portrait mode of a 4 inch phone, that's fine it looks alright, but then that same layout on a 10 inch tablet in portrait is now 3-4inch wide, that's not great looking.
"So what" you say, make it wrap content, okay then so the button now only fills up part of the width on phone, still looks okay but then on a tablet you have huge amount of space now either side of the button, maybe that's looks okay, maybe not.
Maybe same button on a smaller screen takes up too much space?
Now apply the above to every single layout element in your app.
Do you think it'll look good, using the same layout, do you think your users will be okay with an app that was so little care to its UI and UX?
SO, in conclusion, yeah it's possible to only use one eg normal, for all devices but it'll probably look terrible on most of them.

how to set layout for different screen size in android

I am working on a app in which there are some textfiels and button when I am running it on different screen size devices it is showing unexpected result as shown in the below image!
[Image 1] http://oi45.tinypic.com/25yvon4.jpg
[Image 2] http://oi45.tinypic.com/xmlqns.jpg
Here in first image some space is left vacant at the bottom due to large screen size and in second image the last row of buttons are hidden due to small screen size.Also for buttons I am using Table Layout.
Is there any way to solve this problem.
That's a broad topic that needs spatial understanding first.
Here's a good place to start - http://developer.android.com/guide/practices/screens_support.html
Long story short, always use point units (dps), try to avoid to hardcoded pixels within your code, position items in a relative way (ie.: in relation to other object - RelativeLayout, LinearLayout, etc) and make sure to take advantage of the power of "values-..." folders.
Example
values-xhdpi (XH)
values-hdpi (H)
values-mdpi (M)
values-land (Landscape)
values-sw600dp (smallest width at least 600dp)
....
Use layout, layout-large and layout-xlarge resource folders to customize your layout files if you care about various screen sizes. Test these layouts on phones, 7" and 10" tablets to cover all of your bases.
For small phones of less than 4" screens (qvga) as well as older devices (wvga), make custom layout files (in the layout folder) and refer to them dynamically in your java code when you detect these kinds of devices. Again, test on these older & smaller phones as much as possible. Borrow some phones from the Sony Device Loaner Program in order to get real-world testing done.
Lastly, use ScrollView to embed your layouts if you want vertical scrolling on smaller screens. Don't go crazy trying to fit everything on a smaller screen. Sometimes scrolling is a natural solution that your users will understand.
You must have to make screen for all devices if you want to solve your problem.Read below document for different screen:-
http://developer.android.com/guide/practices/screens_support.html
or
You can use weight or layout weight to prevent this problem.

Android: support multiple screens

I am trying to make a application in Android. I want that it should be able to run on multiple phones of different screen sizes, so i studied support multiple screen on developers and according to that i have to create 3 different xml files for supporting three different screen sizes and also 3 different types of images for each type of xml file. But on a blog i get the idea of doing this by using current screen size method. So i am confused what i should do. means which is optimized and performance increasing way. And which one will be more perfect for supporting all types of screen(except extra large screens)
Defining height, width and other parameters in the XML file is the better option rather than on run time.
Because XML files works as metadata (data carrier) to the activity and avoids alot of confusion when onCreate mothode in called.
Plus, create different folders for image quality (hdpi,xhdpi,ndpi,ldpi)
7 inch device use mhpi
10 inch devices use hdpi and xhdpi
While NEXUS tabs use hdpi and xhdpi irrespective of their size.
Mobiles use ldpi and ndpi.
Beauty lies here is that android device automatically pick-p the suitable content when found, i.e layout and image.
If not found it would first search other Layout folders,e.g a layout not found in x-large folder then it will search in large,then medium, small, which one of them suits the best ,(if a layout is not found in its respective folder).
Nexus will create alot of trouble for you.
To check how your layout would look on different devices, try using the options, which tells you how it would look on that device with those height width, present in the Graphical (view of a ) layout.
You can use three different layouts for different screen sizes ,and android will pick the suitable layout , but Using three different layouts for each type of screen format will not be a good idea , because it will cause problem in handling all layout , if screens are less then its fine but if number of screen increases it will get difficult . Like if you forget to add change in one of the screen size it shall crash with any exception .
What you can do is keep images of different size in different folders and practice layout to make standard in one layout by using layout weights , and margins in in dp .
See my this answer
Table Layout spacing issues
and check this layout will look similar for all screen sizes.
If your design is same for all screens sizes you can use dp and have only one xml for all screens.
But you should support icons for all screens.
I think it's less confusing David Ohanyan way, but forgot to say something...
Whenever you can, use styles in your xx_layout, images, etc, so you'll have 1 layout.xml and 3 styles files inside folders: values, values-small, layout-large.
At least for me, it's less confusing than opening 30 different layout files.

Android layout screen resolution problems

I have almost finished my app for android, the problem is when i test it on multiple screen sizes the layout of items such as padding etc, seems to be incorrect. I don't understand how I am supposed to support all screen sizes, because I have used all 'dp' values for the text and sizes for padding etc. I am using the 'background' as an image which fills the screen, and the background includes the layout of buttons and boxes that will have textviews overlaying them. I have been testing on my HTC desire and I have just noticed this issue. I assumed that it would all be okay seeing as I have been using dp for all measurments etc. Any tips to fix my layouts would be appreciated as my app is pretty much good to go apart from this :(
Read the following links very carefully you will get the best way to do:
Supporting Multiple Screens
Support for Multiple Screen Resolutions
Support for additional screen resolutions and densities in Android
compatible-screens
MultiResolution - Multiple Resolutions

Categories

Resources