Adobe Air Mobile App: Responsive sizing of Elements - android

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?

Related

libgdx -> camera and viewports

I have made my game, which scaled accordingly to a % of the screen width with the Gdx.graphics.getWidth() method, and it works perfectly on all screens.
Now I am trying to learn viewports, but seems like there is a lot more trouble, like when does it take in world coordinated or when does it take actual screen pixels.
Do I have to constantly convert beetwen these two measurments? It seems like there is alot more trouble, than if I just scale it the old fasion way...
I can use the whole screen, and manually make the pictures non streched, if I used a FitViewport I would have like blackbars and the game would be totally different.
Any clear suggestions to why to use these ports, cause I cannot seem to understand them...
The thing is that you do not have to do anything especially making any conversion.
Viewport is a kind of tool that handling your app's rendering on many types of screens (I mean many other ratios) and you do not have to worry about it anymore.
Only thing you have to do is to "tell" viewport what is the size of your screen and to handle screen resizing by updateing the viewport. Then you are treating your app like it would be always for example 800 x 600px no matter how it looks actually.
The way your app will render depends on what viewport implementation you will use. For example:
FitViewport will fit your screen to device and add some black bars
FillViewport will fit your screen to device and cut off overflowing part
and so on...
The a look at official Viewport libGDX tutorial. Also you can take a look at this thread to get some information how to deal with viewports.

How to make proportional layouts in android?

I have a design that I need to follow in my app. In it there are several buttons, images and textviews placed all over the screen (some are aligned to the left, some to the right, some are centered etc). What I need to do is make all those elements appear EXACTLY as they are in the design image. The problem is, if I try to do this using dp, it can be wider or narrower than the design image specifies, and it depends on the properties of the screen. (I've had an app where I did it all in dp, and on my high-res phone it works perfectly, but on my friend's older phone it cuts away the edges of the activity)
My question is, what elements do I use for this? I've heard of using weight in Linear Layouts, but how to make items different width and height and position them all across the screen how I see fit? How to make sure it looks exactly the same on all screen sizes?
Thanks in advance! :)
Edit:
The point is, I need the buttons to be just as they are on the screen (this will be a listview element, I'm trying to make an xml for it). The distance, proportion, everything, it needs to scale to the width of the screen and be this size and distribution. And, I'm not just looking for a solution to THIS particular problem, I want to learn how to do it in general...
You don't. For very large and very small screens, you use separate layouts that scale the sizes, completely drop parts of the UI, or lays it out in a different manner. It's absolutely silly to think you can fit all the stuff on a 10 inch tablet and a 3.5 inch phone. If your designer expects that, tell him he's an idiot and he needs to get back to work.
For a more general answer on the best way of laying things out- it depends on the effect you're trying to get. You should never use pixel counts, and dp should only be used for small things- a bit of padding between 2 fields. Most things should be done via layout, either by using a linear layout and getting things in rows/columns, or a RelativeLayout and describing how to layout views relative to their siblings. But even with these tools you will not be able to fit on all screens and look good.

Vertically long user interface

I made a UI with many UI elements such as button and it takes a lot of space vertically.
The UI fits on my phone (it's 16:9 like many), but on phones with a different screen ratio, the buttons on the bottom are cut off of the screen.
I'm using a linear layout. How do I fix this?
Instead of trying to create a UI that is like an image and displays at a fixed aspect ratio, start thinking about designing for resizing. To accomplish this, you need to make decisions about what in your layout must be fixed in size, and what can acceptably resize or scroll.
Importantly (and this is my own stylistic opinion), you should avoid layouts that clutter the screen or fill it with detail. Your layout sounds like an input form of some sort; one solution in your case might be to let the controls in the upper part of the menu scroll, while anchoring the buttons at the bottom of the screen, or to just place the whole layout in a scrolling view. But ask yourself: will this be user friendly? I suspect this solution will look dense and (on really small, resistive displays like that of the LG Vortex) become hard to interact with.
Try to separate your UI into easy to comprehend little "nuggets", omit unnecessary information, and if you must, split the UI into different activities or fragments.

Fastest way to do peripheral clipping

In my Flash AS3 app, I am using
stage.scaleMode = StageScaleMode.SHOW_ALL;
because graphically I want it to be workable out-of-the-box in all kinds of different mobile devices. It works a treat because it does a "best-fit" to the device's screen and simply "adds" black borders around it.
For example, in 4:3 screens it fills the whole screen nicely:
while in 16:9 screens I get black borders on the left and right:
Now here is the problem: when I am moving a display object "off-screen", I don't want it to be rendered inside those black borders.
The question is this: what is the fastest way to "clip" my app - considering I am targeting mobile devices? I have a feeling that a
stage.scrollRect
will blow things up performance-wise...
EDIT : I am using <renderMode>gpu</renderMode>
scrollRect is actually great and even makes your application perform better, unless you're using GPU composition (in which case it really degrades performance). So I'd suggest you trying it first.
But a good alternative solution (as crazy as it sounds) is to just have a huge rectangle with a hole on it on top of everything, as the last children of your stage. So suppose your stage is 640x480. You'd have a black rectangle on top of everything with dimensions of, say, 1640x1480, and with a hole of 640x480 pixels inside of it to let your content be visible. It's a cheap way to mimic a mask without forcing recomposition of the pixels inside that area.

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