Why mostly values are multiples of 8 in Android xml? - android

Why most of the time if we have to create a margin, padding or anything inside xml we use multiples of 8 or 4?
I was trying to know what is the possible reason for this? Why isn't it an odd number mostly ?

Spacing methods and layout grids define structure, hierarchy, and rhythm in your design. When correctly used, they reduce decision-making and help establish a rational approach to type scales, positioning, sizing, and spacing.
Base Unit
The base unit defines what every measurement will be a multiple of.
This keeps designs consistent, improves communication with developers, and reduces the number of decisions a designer has to make.
The most recommended base unit is 8px because it makes scaling for a wide variety of devices easy and consistent.
This is because most screen sizes are divisible by 8 and because 8 is itself an easily divisible number (8/2=4, 8/4=2).
On other hand, as Material Design (is a design system – backed by open-source code – that helps teams build high-quality digital experiences.) explained,
All components align to an 8dp square baseline grid for mobile, tablet, and desktop.
Icons, type, and some elements within components can align to a 4dp grid.
Refer to these articles for more details,
Everything you need to know as a UI designer about spacing & layout grids
8pt Material Design GUI Templates

Related

What is best best approach to make a 2D map that will be a level selector in android using native android components?

I need to make a 2d map which lays out levels for a android game. It is low budget and I need to make it with native android components.
The map goes to a finite number of levels so I do not have to generate the map dynamically and using the technology suggested in http://forum.unity3d.com/threads/smart-2d-levels-map.267394/
will be a bit of a over kill.
I also got a heap of motivation from How to create a 2D Map to use in a Android Game? as they said that it is possible to achieve what I need without a engine.
All I am enquiring about is if I should make a scroll view with a relative layout inside and then align the real buttons relative to each other in px (as dp will make that the images will not line up in all cases as the background which is a image is in px) or should I approach this completely differently.
My biggest concern with my initial thought out approach is that the different screens will mess with the locations of the buttons and that if I make everything px that the screen will be to small for high density screens.
I have considered to make different layout files for the different screen sizes but before I start developing I thought that it will be best to get another view point from the community
Thanks in advance for the feedback.
I have played around with using a relative layout and this seems to work on all screen sized after I set the height and width to static dp values. This makes the ratio constant and makes the solution acceptable on any screen size

Need approach for screen development in android

I need expertise advice/approach for starting screen development in android.
I got a couple of screens from my customer and i need to develop them.
I went through lot of tutorials and understood about supporting multiple resolutions and sizes all that is fine, but i want to understand basic things like how to properly place the UI elements. Should we need to use any tools like photoshop for measuring units like top bottom right left etc and place the UI element in xml or just by approxiamtion we will place the UI element.
For example consider this screen https://d13yacurqjgara.cloudfront.net/users/137442/screenshots/1234960/attachments/166804/Login-screen.png.
for ex How you will place the user name and password edit texts. I mean how much of top left bottom margins will be used. is that just approximation or need to be measured using tools like photoshop.
Say i used photoshop and got the values in pixes if i convert them to dp and use those values in layout will they support for other screen sizes??
are there any tools which can take the screen iamge which i posted above as an input and generate the android layout from it.
You don't need Photoshop to measure the units. The Android SDK has several layouts with their accompanying properties and options that will allow you to pretty much achieve any UI implementation. imho there are not tools that will 'take a screen image and generate the android layout from it'.

How to position images at the same spot all android devices?

I have to position the images on my layout such that it does not change its position with varying screen resolutions. They should be exactly where they are placed. layout_weight attribute can be used with linear layout. But I am using relative layout and I am dealing with cropped images. Any solution on how to position the image views? Setting out margin height and width is not worth.
In short - you can't. Devices have different resolutions as well as screen sizes ratio. Thus it's impossible for the app to look same because there is no same definition in Android. The only way to design an interface - is to use bindings to other objects or parent view's borders. Try to investigate what are the rules, e.g. "to the bottom of the picture with 10dp gap" or "next to the TextView" - and it's the constants that are kept on every device.
I can't imagine a scenario where this makes sense but it obviously must exist since the Android team built support for it. The docs on the dimension type clearly state that it supports "mm" and "in" as qualifiers for millimetres and inches respectively.
That should get you what you need but I would advise reevaluating that requirement, as it would make design a massive pain.

Android - what should be the dimensions of the background images of the header?

I am trying to make a header and it is going to have 4 or 5 buttons...I am not sure yet.
The text of those buttons will vary in length and also the different devices will have different widths, and also there are the horizontal and vertical views for each device. So I am not sure what my background images should be in terms of height and width so everything fits nicely on the screen.
What is the recommended or best practice way of handling this?
Thanks!!
You need to read the android docs, specifically Designing for Multiple Screens.
Perhaps Supporting Multiple Screens as well.
It will take you through what you need to know/do to set up and support those devices you wish to.

Android Design versus iPhone Design, Relative versus Absolute

I have a client who wants me to build an Android version for their existing iPhone app. The design of the iPhone doesn't use any native iPhone elements. It's basically some sort of grid with containing images, buttons, text, etc. Of course it was easy to make the iPhone app because of the fixed pixels widths/heights. The basic grid that defines a screen is loaded via a XIB file, and I load the custom buttons in the right containers in the grid by specifying the exact coordinates.
Then comes Android...
Our client wants to target 3 specific tablets (1024x600). They have given us designs for a ~600x980 portrait version of the app. It is not recommended to use AbsoluteLayout in Android. What is the easiest way to make sure that I can scale it on different devices but that it will look like the given design on the 3 target tablets.
One idea I had (which I'm not sure about whether I can implement it) was:
Get screen width in pixels and height
Based on width/height ratio of the design, pad with bars on top/bottom or left/right
Still do an AbsoluteLayout based on this information
I'd rather not do it this way because it sounds involved and counter to the Android way of doing things. Another issue that is created by scaling is the following. There is a bar of buttons that have a lines separating them. These lines are 4 pixels wide. Obviously, when you start scaling, this is going to mess this up completely. I can't seem to find much information about this s
You probably want to start here:
http://developer.android.com/guide/practices/screens_support.html
But quick points are probably
Do not use an absolute layout. Your life will become terrible
Handle sizes in density independent pixels so they will scale properly on different devices
Use ninepatch images so that when images stretch they will stretch in the proper regions maintaining your 2px borders ect.
Take advantage of the different resource folders for images at different densities (drawable-mdpi vs drawable-hdpi) and layouts at different sizes (layout-small vs layout-large). The latter will allow you to have separate layouts for your tablet devices.
Best of luck :-)

Categories

Resources