How to design a layout that should support all screen size.
See the Images below..
How can i make all screen looks properly with same images?
Edit:here larger screen [WXGA] displays in proper way. becoz i used image button there to change alphabets(Eg A,B,....)
Yes I am totally agree with Farray's answer. You should create separate layout files and put inside the particular folder like layout-land, layout-large-land, layout-large, etc. and create different drawables for the different densities and put those drawables inside the suitable folder like drawable, drawable-hdpi, drawable-ldpi, drawable-mdpi, etc.
For example:
Update:
As you want to put buttons for all the alphabets, in that case you should use GridView and define your custom adapter with ImageButton and set the same adapter inside the GridView, I am sure this will looks perfect as per your requirement. For your reference, I would like to suggest you to go through this: http://www.firstdroid.com/2011/02/06/android-tutorial-gridview-with-icon-and-text/
Unfortunately it's not as simple as scaling the images larger. That will produce very poor results on larger screen formats.
The proper way to support multiple screens is to include different resources for different size categories. At the very least you should create separate layout files for small and large screens and include different drawables for the screen densities you want to support.
There's a lot of information at http://developer.android.com/guide/practices/screens_support.html Maybe give that a read and then post additional questions if you have them?
Related
Which is the layout to use which doesn't have a difference in different screen sizes. Linear layout or relative. I had a relative layout and when I run the app on a 4' phone, the icons were way closer. In a 5' phone the icons were a bit away. What's the best way to have a constant XML which doesn't change by screen size.
For example.
I had this app in linear layout which contained 3 images in horizontal orientation. In the design view the icons were perfectly same and equidistant. But on the device, the third icon was smaller. Why
You can't achieve perfect layout for every device with just single layout file. For best results you should make different layout files for different folders used with images designed accordingly. For more information read Android Developers' tutorial from the following link
Supporting Multiple Screens
Over and all, you need to create different layouts/drawables for supporting all the screens. It depends on your requirement, say for example, if you would want to include 2 buttons in small screen and 4 buttons on large screens then obvious you have to create different layouts.
If you would want to display same number of buttons in all screens then I would suggest you to prepare different set of images/drawables and include them in your project. Here you don't need to do anything other than placing images in particular drawable folders.
One more thing, If its a plain background then you can create 9-patch image so that it can stretch with whatever size you want or your device supports.
More study:
http://developer.android.com/guide/practices/screens_support.html
http://developer.android.com/training/multiscreen/screensizes.html
http://developer.android.com/training/multiscreen/screendensities.html
http://developer.android.com/training/multiscreen/adaptui.html
I am trying to define following layout folders
layout/my_activity.xml
layout-large/my_activity.xml
layout-xlarge/my_activity.xml
layout-xlarge-land/my_activity.xml
layout-land/my_activity.xml
layout-sw600dp/my_activity.xml
layout-sw720dp/my_activity.xml
Is this the complete list?Am i using all the possible layout folder combinations to support all screen sizes.
Sorry if it sounds silly but i am trying to confirm different layout folders i need to make for my App...
Take a look at this:
http://developer.android.com/guide/practices/screens_support.html
With the new qualifiers you can define size qualifiers based on arbitrary dp so you can't list "all the possible combinations".
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.
What is the standard/best way to define sizing for elements in Android layout files to account for Android devices with all types of screens?
For example: I've been using a LinearLayout to arrange multiple child elements (TextViews, Buttons) one after the other horizontally or vertically for a ListView. However, on a smaller device, I may want to scale the elements down or shrink some elements but keep the others fixed.
I'd appreciate input. Thanks
There's an entry in the android dev guide for that: http://developer.android.com/guide/practices/screens_support.html
You can use drawables in drawable-hdpi, drawable-mdpi and drawable-ldpi. Test those in different screens in the emulator and tweak the sizes appropriately
Please read supporting multiple screens.
In a nutshell: It's very easy. You can create subfolders of each folder in the resources (like layout-small, layout-large, layout-hdpi), and add different versions of your layout. The system will always fall back to the layout folder if none of your specializations (hdpi, large, etc) match.
I'm at the planning stages of my first proper android app. Part of the brief is to have a very "good looking" interface (aka, plenty of graphics). As I'm a web developer, and I'm used to the CSS way of doing things, I'm struggling to understand how I will cater for all the different resolutions when building my layouts. To cut it short, my question is this: how do I build complex, image heavy views that can be seen in apps such as SoundHound (example view here, for those not familiar with this app: http://getandroidstuff.com/wp-content/uploads/2010/09/SoundHound-Android2.jpg)? Is there a way I can tile images in a similar way to the way I'd tile in CSS?
It is important that you know how all Layouts Views work before you start designing your main layout. Android OS by very design supports stretching of views and GroupViews. You need to use dp (density independent pixel) units.
In the example you provided, there are some nice nine patch PNGs. Check C:\android-sdk-windows\tools\draw9patch.bat if on PC. These pngs stretch properly as backgrounds for any resolution.
Linear layout have weight which allows you determine how much space will each child occupy, similar to the old column width for tables in %. Just like in old hml, to make a rich layout you use nested GroupViews (e.g. LinearLayout, RelativeLayout etc) and populate them with children views like ImageView, TextView and son on.
It is possible also to have text styled with <b>,<i> tags and have
<img src="DrawableName">
see an example: Html.ImageGetter
Opposite to a nested layout would be to use the RelativeLayout and determine the position of each child view by its top and left margin anywhere on the screen in relation to the top-left corner of their parent RelativeLayout.
Android has some conventions, that help you out when it comes to different screen sizes, screen densities, screen ratios ...
For example there is a directory called "drawable" where you can put the image resources for your application. However, if you want to ship your application for devices with different resolutions, you can create additional folders named "drawable-ldpi", "drawable-mdpi", "drawable-hdpi". The ldpi folder contains image resources for low density screens, mdpi is meant for medium density and hdpi meant for high density. The folder names are part of the Android conventions. When loading an image resource at runtime e.g. on a high density device, the system is looking for the image resource in the drawable-hdpi folder. It there is no image with that name, the system will look in the drawable folder.
This concept also applies to the xml layouts you define in your "layout" folder. Maybe you say that the layout homeScreen.xml needs to look different when the user switches from portrait to landscape mode. Then you can create a folder "layout-land". You create another homeScreen.xml in there and change its apperance to your needs. At runtime the system detects the current mode. If in landscape, it will first check if there ist a folder "layout-land" and if it contains the layout file with the correct name. If not, or when the user switches back in portrait mode and there is no folder "layout-port", the system looks for the layout file in the "layout" folder.
This is only a small part of it, but I hope, you got a first glance and everything was understandable. Further information can be found in the official refrence