How to write CSS for mobile cross-platform site - android

iOS is easy, because the pixel-ratio is always either 1 or 2, and the target dpi is always pixels/ratio. Android, however uses 1.3, 1.5, and in some cases 2.25 for a pixel-ratio. I'm not aware of any way to set the target dpi to pixels/ratio for android devices, which would be an easy fix, but I imagine a pixel-imperfect solution for any display whose physical pixel count is an odd multiple of it's dips count (those 1.3's, 1.5's etc).
Right now I'm basically writing css for each -webkit-min-device-pixel-ratio, and just multiplying my px values by that ratio manually (with slight adjustments for rounding). Using ems works great for fonts and a few other things, but I have to use pxs for positioning and sizing of elements if I don't want half, empty, or overlapping pixels.
Is there a better way to do this?
If not, what is the best way to deal with background-images. I really don't want to have to re-write every single background-position for every icon for each ratio simply because I am changing the background-size for each device-pixel-ratio.

You can try using the viewport meta tag. It lets you match width to the device's width. It also allows you to set initial scaling, set bounds on scaling, or even disable scaling. And here is a link to a relevant Stack Overflow question and answer on using the meta viewport tag.

Related

iOS) How to set image's size and coordinate as the same as android

I'm developing ios app for a service that already has android application.
I have psd files and png files corresponding android one.
But I don't know how to set image's size and coordinate as the same as android....
Is there a way to follow android's ratio constructively?
I'm just setting imageview by eye measurement...
By eye measurement, I calculated ratio, size(width,height) and coordinate...
I want to make images set as the same as the android's one.
I'm just using 'aspect to fit', that makes this problem less heavy but not perfect
Calculating everything manually will be horrible when you want to support multiple devices of different screen size. Use constraints if you want to scale the UIImageView to a certain ratio of another view.
Please refer to the auto layout guide at https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html

Adobe Air Mobile App: Responsive sizing of Elements

I still have trouble understanding the possibilities of Scaling my UI in a responsive way in my Air Mobile App. On the web I'm familiar with it and the use of media-queries.
I dont want to scale my whole UI up and down or even stretch it (e.g: I use the camera in one DisplayObjectContainer, so this would be really bad for the performance to scale this.)
I currently go down the road defining all the container sizes by percent, but that is getting pretty ugly pretty fast as it leaves me with 68.95px values. I think this will get me in trouble one day as blocks appear not crisp anymore. If I round the values, I might have 1px gaps between Elements.
Currently I have this Setup. The idea is, to give every main Component a (maybe invisible) empty background-child. These can then deformed by width & height by any desire. The inner Elements of any Element (button, logo, etc) are not affected by the deformation of the bg and can then be arranged accordingly (as I now have position and size of this container - like in css).
But this does not feel like it is the right way.
Is there a magic lib/class I dont use currently and that allowes me to build in hard pixel for a defined setup and behaves appropriate when it comes to different stageWidths, DPI, etc?
What are your approaches for this problem?

Android Paint settextsize

Ok I know that there are already many questions that ask the same thing as what I am asking, however the problem is that none of those solutions have worked for me or are what I want. My problem is that when I use the setTextSize method of the Paint class, the text appears to be too big on smaller screens, and smaller on bigger screens. What I want is for me to be able to change it to the size I want on my device, and then on any other device the size should change accordingly (scale down, scale up) and it should appear the same way (NOT the same size) on other devices. And I have already tried multiplying the density by the dp I want and all that other stuff but it doesn't work.
First off, any size you use should be based off of sp- scaled pixels. Units in sp scale with respect to the user defined default size. This is to people who are hard of seeing can choose a larger text size, and all text will scale relative to this choice. You should not be designing text in either dp or in px, as neither of those will scale with the system font size. When you call getTextSize/setTextSize it should be treated as sp.
As for it looking the exact same on all screens- you're not going to get that, because different OEMs use different default heights and different default fonts, not to mention the user can override either of those. Pixel perfect should not be your goal. Which is good, because it isn't actually possible.

Android: Adjust sizes programmatically according to screen size

Is it a bad habit to get the width and hight of the device and set images/button sizes programmatically accordingly.
I find it inaccurate to use different folders for layouts and densities as it gives me wierd results on some devices (on top of the inacurancies)
Your experience is appreciated.
Thank you
Yes it is very wired thing to make the layout for the all supported screen of android. And there are lots of screen resolution available in market.
Once i have made a Demo and it Works for me. I have made one Button which height and Width is same. Now i have set its required height and width as per the one Screen in which it is looking perfect.
After that i have calculated the pixel that it required to make it Possible in that screen and based on that i have applied it to all screen.
Now it works great in all device with any density and resolution.
So if there is any view that generate at run time and you want to set its height and width then the best way is to calculate its height-width ratio and use it.
hope it will helps you.
Enjoy Coding. . . .
:)
Well, most of cases you will have layouts which are, or will become, complex, and it will be difficult to calculate the positions programmatically.
And it will be also a disadvantage mantaining it, because you will not be able to use the interface stuff (grafic layout and so on), and other people, or yourself, will not understand the calculations the same way they would if they see the views in XML. Reorganizing, changing somewhere a position could be painful.
You also will be working frequently with bitmaps, which have a fixed size, if you calculate the dimensions programmatically and stretch they will not look good. At least you would need different set of bitmaps and load accordingly.
It helps if you for example use relative layouts with rules (like above of / align at the bottom of the parent, etc), linear layouts with weights, and dip (density independent pixels). You should do programmatic layout only when it's not possible in other way. Or in some certain cases where it really-really makes things easier.

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