How to make UI in android for different devices - android

I'm fresher in Android & Coding. I have a task to design a popular game dots and boxes, for references https://en.wikipedia.org/wiki/Dots_and_Boxes . In this I have 7X7 cicles and used imageview to display all the stuff. My problem is how to design for multiple devices which looks as designed.

There is a great tool that lets you turn one image into multiple images for different screen densities: https://romannurik.github.io/AndroidAssetStudio/
There a few options there for generating the images, i use the Generic icons option since it allows an option for resizing the image.
if you use the generic option then:
Source: click image and upload the image (the circle for example).
Size and Padding: the defaults for size and padding are usually good enough.
Color: defaults to blue just move the seekbar to the far left in order to use the original color of the uploaded image.
Name and Download: at the bottom of the page you can rename the image see a preview and download as a zip.
Import: in the zipped file will be a res folder already structured properly by drawable densities and ready for you to just drag and drop into you /src/main folder.
P.S. Thank you to the person that made this tool your a genius and a life saver.

First of all use the unit dp for defining measurements. In addition to that, you have to define several values folders, where you define dimensions for scaling tablets or phones. E.g. define two values folders like:
values-large
values-xlarge
Now define a dimen.xml file inside this folders, where you can put your measurements in (unit dp) for the corresponding screensize. Define a measurement like this:
<dimen name="value1">17dp</dimen>
Then embedd this sizes in your layout xml, like:
android:layout_height="#dimen/value1"
Depending on the screensize, the system will load the correct measurements from this folders, e.g. if you have a screen size large only the defined values in folder values-large will be loaded. So instead of creating different layouts, define different measurements that can be loaded by the system automatically. For more information about this, also have a look at https://developer.android.com/distribute/essentials/quality/tablets.html

Related

Different Text Sizes for different Screen Sizes, using what ratio factor?

Hello I am using different textsizes depending on different screen sizes.
Like:
values-small: dimens.xml -> ?
values-normal: dimens.xml -> 10sp
values-large: dimens.xml -> ?
values-xlarge: dimens.xml -> ?
I want to know if there is a formula to set the right sizes depending on small, large, xlarge instead of setting sp size by testing it on different screens^^?
second question: is values-normal neccessary, isnt "values" folder == values-normal?
third question: what happens when I declare dimens.xml for small, normal, and large and the device is a XLARGE device will it use dimens.xml from values? or valuse-normal? or the next smaller one values-large?
thank you
I want to know if there is a formula to set the right sizes depending on small, large, xlarge instead of setting sp size by testing it on different screens
Not really. Many apps do not change their font size at all based on screen size, just as most Web apps do not change their font size based on browser window size. Of course, you are certainly welcome to specify different <dimen> resources for different screen sizes, including dimensions for use with text. And there's nothing stopping you from using an algorithm like the others suggest; just understand that there's no real reason to use that algorithm. To put it another way, a graphic designer should be telling you how big to make the text, not a calculator.
Moreover, the -small, -normal, etc. buckets are not used as much anymore, in favor of the more flexible -wNNNdp, -hNNNdp, and -swNNNdp buckets.
isnt "values" folder == values-normal?
No.
Suppose you have res/values-small/, res/values/, res/values-large/, and res/values-xlarge/. Further suppose that each resource set defines a text_size dimension resource, and you use that in in layouts (e.g., #dimen/text_size).
A -normal device will then pull from res/values-small/, as -small is for small screens or larger. Your res/values/ version of the resource will never be used. Hence, the typical pattern would be not have res/values-small/, putting your -small resources in res/values/, and overriding that default value in res/values-normal/, res/values-large/, and res/values-xlarge/.
what happens when I declare dimens.xml for small, normal, and large and the device is a XLARGE device will it use dimens.xml from values? or valuse-normal? or the next smaller one values-large?
It should pull from res/values-large/, as that is the closest match among the qualifying resource sets.
This is the common problem in majority of Android projects to support varied screen sizes.
In short, you can make use of scalable DP and scalable Font approach.
Android project structure inherently allows specifying different font size (SP) and margin values (DP) by defining them in dimens.xml files for supported screen sizes. But the problem that still remain is - what values to be used ? UX designers normally provide style guides for only one set (e.g. 360x640 DP screen size) and don't provide for all other supported screen sizes. So the problem to use right vlaues for other supported screen sizes still remain unanswered.
One good solution (per my understading) is to use readymade scalable dictionary of dimens.xml files, something similar to the dictionary of files provided by this library. After adding these xml files to project, you just need to use the keys in your layouts, then Android automatically uses font/margin value from respective directory. Please refer here for visual difference - with and without this approach.
I use the ratio 0.75 : 1 : 1.5 : 2 same as for DPIs. It works fine.

Relative "res/values" folder in Android to scale styles based on screen size and resolution?

I wonder if it's possible to have a folder such as res/values-small or res/values-hdpi in the same way that it's possible for the layout folder? I'm thinking about styles that should automatically scale depending on the screen resolution and size.
Or do I simply create a separate style for other resolutions in the same values/style.xml file?
Yes you are right all the names you mentioned are valid. To experiment more with different filenames use ADT.

Where to insert images in eclipse for android

I am new to Android and I need to use images in my XML file.
A tutorial says that I have to place them in drawable directory, but I can't find it as I find drawable-hdpi, etc.
drawable folder is divided into into three part according to device screen size h- high, M- Medium, L- Low because in android different size of device available in the market and android device screen divide into three type h,m,l based on density specific according to device size android pick the image from specific drawable folder h ,m ,l if you dont want to density specification in your application then add new folder with the name of drawable.
I hope it is more use full to you.
You can create the drawable folder yourself by right-clicking "res" -> "New" -> "Folder" and naming it drawable.If you do not need your images to be density-specific, you can put your images there.
you can create your own drawable folder in res directory. But remember keep the images in that folder which are common for all screen size devices. drwable-hdpi means this directory contained the images will be loaded when the device has higher dpi. similarly drawable-mdpi and drawable-ldpi are there.
Those which you found are drawable folders.. Insert the images in all three of them. So that at time of change in definition of screen images can be changed accordingly. For now, Insert same image in all three of them.
You can create your own drawable folder. But its good to use these at first then when you run your application on device you will come to know the difference.
drawable-hdpi drawable-mdpi etc are the different type of drawables . you can keep your images in these folder (any one at the initial level).
But they have some diffrence according to the resolution of the screen & density of android device. Further you can check the diffrence between them and keep the images as per need.
see this for more details: Explain the difference between drawable, drawable-ldpi, drawable-mdpi and drawable-hdpi
and Supporting Multiple Screens
you can create a drawable folder in the /res folder of your project and put your images there.
drawable-hdpi(mdpi/ldpi) are used separate different resources for different type of screen. take a look here to know more about multiple screen handling
I realize that this question is rather dated, but...it came up when I Googled the issue of inserting images into an Eclipse Android project, so....
Actually, those folders are mipmaps and they are used by the graphics subsystem to provide seamless zooming, as well. I would suggest creating proper mipmaps using an editor, as opposed to providing only one resolution choice.

how to solve this image scaling problem in android?

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?

android - How to build complex views that stretch?

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

Categories

Resources