Why should we use xml layouts? - android

After some years of Android development, i took months wondering why should i use xml layouts to make the UI of my Android App.
I understand that part of MVC and real-time graphical interface design.
If im wrong please take me out of ignorance and forgive me but , I´m Unable to set a view´s position, exactly, 8% of screen width for margin and 70% of screen width for width, for example.
Creating the UI in that way and taking care of screen aspect ratio ensures the app will look proportionally exactly the same in all devices.
As this post sums it up, we are told to use dip units and a nice bunch of xml files for every layout of our app if we want to support different screens. (Why they call it density-independent if we have to make it different for each screen density?)
But, even doing that, as (again) the Google Doc says
The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion.
And in place of not necessarily they should say mostly never looking at the incredible number of different devices. Depending of your project, this may be a problem. (Or do you want your client looking at your "slightly-decomposed" UI on a who knows chinese device)
I could ask the same for the image resources, but that whould be another question, i use to put the highest resolution on -nodpi then downscale by code to screen-width-dependent desired size, instead of putting 10.000 images at all resolutions.

Creating the UI in that way and taking care of screen aspect ratio
ensures the app will look proportionally exactly the same in all
devices.
This is the way Apple does it, and this why when you open a folder on a 9.7 inch iPad with beautiful retina display, it only displays 9 icons.
A tablet is not just a bigger phone. It's really not. Also, iOS devices have mostly the same aspect ratio, so that's how they took care of the aspect ratio.
On Android however, you can't just say that you "took care of the aspect ratio" problem and that this problem magically goes away. Your best bet is to use Android best practices to handle aspect ratios correctly.
That being said, don't over do it either. You don't need to use all 8 density buckets for instance. Look at the official dashboard to see what devices people are actually using, before you try to optimize for every scenario possible.
Also, you don't have to listen to Google all the time. For instance, I am sure that Google would love that you translate your application so that it's available in more then 68+ different languages worldwide, but what's good for Google is not necessarily good for you. Android actually lets you choose the tools you want to use to make your application. They don't force you to use any particular one.

Related

What do I have to worry about when making a mobile game for different phones?

I want to get into mobile game development but before I get started I want an idea of what the process is like so I can choose the right tools.
Obviously screen resolution is the most obvious, but what other things have to be changed so it will work on multiple phones?
This is an enormous topic. The most basic design is to have a rectangular play area that can be stretched to fit the screen you are using. Whether you keep your original aspect ratio or "match_parent" for both dimensions is up to you.
You've recognized that that won't take full advantage of screens of different resolutions so many courses and tutorials will walk you through learning to design a relative layout that will arrange and size some elements according to the available space and other elements according to how much space the content needs. You'll also eventually provide images of different resolutions that will be used for different screen densities.
I recommend you jump right into game development before understanding this topic fully. There are many intricacies that you'll come to understand as you work with them.

Cordova/general: Easiest way to develop for different screen layouts?

I was really wondering.. What is the easiest way, in combination with Phonegap/Cordova, to make your app support multiple screen resolutions? Mainly all Android ones, such as 480x800, 720x1280x 1280x720, 800x1200, etc.?
I've already created an app with percentages only (Click) (Which would show great on all 16:9 screens, but it doesn't), but that isn't enough. Only on screens with 720x1280 it shows ok.
Especially the option to deploy both for phone as tablet seems impossible due to the whole different orientation.. and the bigger screen leading to a whole new UI (for best user performance).
The only way I could think of is creating a different stylesheet for EVERY resolution, which could take up a huge amount of time; i guess?
Looking forward to feedback, thanks!
First, code responsive where ever possible. Instead of media queries (which are messed up on android 4), you could try https://github.com/biodiv/cordova-screengod
After deviceready, you call
screengod(['path/to/your.css'],function(){
/* do your stuff */
});
and it automatically adapts your css to look the same across all platforms/screens.
Personally, I use Bootstrap and their Grid system. It takes a minute to figure out how it works and how to get it to fit with what you are trying to do but once you do, it is amazing. Documentation is here.

Is it worth my time producing ldpi assets for Android applications these days?

I'm currently building an application for Android (a game). So far, I've created assets for all devices, from ldpi all the way up to xhdpi. I'm building the application for Android 2.2 and above.
Should I stop producing ldpi images?
It would cut down the time it takes to produce the graphics fairly significantly. On top of this, I don't think that very many devices (commonly used) these days actually fall into the ldpi category.
Thoughts?
There are only 3.1% of phones with ldpi screens (as of 1st Jan 2016). Here is the statistics about devices and their screens. You can decide whether to support them or not.
True, but to build your brand image, you have to do the job perfectly, for everyone. Even if there are a few tens of users who use low dpi, it's totally worth it. :-)
You could if you like. you could set a in code aspect ratio resizer, and size all the images accordingly when loading them. So no matter what screen you play on, they take up the same percentage of it. This significantly cut down graphic time, and looks great.
another way you could do it, is get Paint.net and simply build the largest graphics first. Then go into Image and Resize, and set the resize to by the ratio difference, say 75%. save this and you are done. Should cut the entire time down significantly as well, and also looks great.
I have done it both ways, and you cant tell the difference.
I have always built my code so that it fits the game to the screen.
for example in a sidescrolling fighter if a character is 5/8 the screens height, and 3/12 the screen width on my testing device, and it looks great>>> you can do a little math, figure out the h/w ratio of the screen any user is playing on, and adjust the image at load time so that no matter the device your image will take up the percentage of the screen you intended it to.
It is suitable to use all image packs, because if most devices support MDPI, but you would be losing market devices with low resolution. Use LDPI.

From .psd to screen

I have a client that gave me a .psd file that contains the entire screen of an Activity with all the graphics. The resolution is 480x800. The client wants the application to look identical to the one in the .psd file. The problem is that different devices have different resolutions and sizes. I know that the density is what really matters but how can I scale the graphics to look the same on all the devices? For example, I exported all the layers and recreated the screen in Android but, for some reason, the screen looks more crowded on a Nexus One (480x800).
One idea would be to create 9 patch images from the graphics and use for ImageViews android:background instead of android:src right?
Isn't it better to have a 320x480 resolution for the graphics? Or do I need for both resolutions? Also, I have to consider the height of the status bar which I understood it is 25dip but I am not certain about this.
So, to summarize, I am interested to find out what is the best way for a client to give you the mockups and graphics so that it is easy for the developer to implement according to the specifications.
That's something that's not easy to solve. Think of a webdesigner, one can't know all the possible resolutions and settings of every browser so he has to scale things accordingly.
In my opinion there are only three approaches here.
First: Let him state what devices he wants to support and only support those devices. Extract the layers with the size of the device with the highest resolution and scale them down on other devices.
E.g. If you have to support two devices with 480x800(2) and 240x300(1), export all images to be 480x800 and scale them down accordingly. Don't write a single application for every device.
Second: Export the graphics with the highest resolution possible and scale them down on all devices relative to the device being used. Imagine, again, a webdesigner. All he does is define margins, paddings, etc. and it will look nice in almost any browser. You should do the same and resize your elements on demand.
Third: Make the application fixed, e.g. define a size of 200x200 for your whole application and just fill everything larger than the screen with a certain color, e.g. black. This happens a lot with java ME applications, they look great on the hardware they were made for and are still playable on hardware that is beyond their time though they look pretty ugly.
Hope this helps,
Robin.

How big can I make an Android application's canvas in terms of pixels?

I've determined an estimate of the size of my Android emulator's screen in pixels, although I think its resolution can be changed to other numbers. Quite frankly though that doesn't eliminate the general problem of not knowing how many pixels on each axis I have to work with on my Android applications in general.
The main problem I'm trying to solve is this: How do I make sure I don't use a faulty resolution on Android applications if I want to keep things' sizes constant (so that if the application screen shrinks, for instances, objects will still show up just as big - there just won't be as many of them being shown) if I wish to do this with a single universal resolution for each program? Failing that, how do I make sure everything's alright if I try to do everything the same way with maybe a few different pre-set resolutions?
Mainly it seems like a relevant question that must be answered before I can come across a complete answer for the general problem is how big can I always make my application in pixels, NOT regarding if and when a user resizes the application's screen to something smaller than the maximum size permitted by the phone and its operating system.
I really want to try to keep this simple. If I were doing this for a modern desktop, for instance, I know that if I design the application with a 800x600 canvas, the user can still shrink the application to the point they're not doing themselves any favors, but at least I can basically count on it working right and not being too big for the monitor or something. Is there such a magic resolution for Android, assuming that I'm designing for API levels 3+ (Android 1.5+)?
Thanks
Hmm, I suggest you read this: Supporting Multiple Screens. That gives a wealth of information on how to handle different screen sizes. In particular, read about its concept of density independent pixels versus absolute pixels. Density independent pixels are essentially pixel sizes that the system automatically scales for you depending on the screen size you're working on. It considers the 'standard' screen as that of the G1, Hero or similar devices, i.e. 480x320 pixels with a density of 160dpi. If the screen you're working with is bigger than that, i.e. the Droid or Nexus One, it adjusts all density independent pixel sizes by 50%.
Alternatively, if you're really talking about canvases, as in, Canvas for animations etc, you can just call canvas.getWidth() and canvas.getHeight().

Categories

Resources