For an app I would like to design the layout from the top down: Start with the full screen size, split the screen size into a grid and place controls in fixed positions in this grid etc. To me that seems to be the easiest way to design an app which fits to nearly all screen sizes. Ideally I'd want to scale other things, too: Cornerroundings, fontsizes etc.
So far my impression is that Android does not want to support this approach: There are mechanisms for scaling nearly everything, but it gets ugly pretty fast: LinearLayout and TableLayout support weights, so I can use those reasonably well, but if I want margins that scale with the screen size I need lots of nested layouts. Is there some design reason for this? It should be quite straightforward to implement a layout which is similar to AbsoluteLayout but bases everything on fractions of available screensize, but no such thing exists.
Why not? Is there some reason why one does not want such a thing or is it just that nobody has bothered to implement it yet?
For a layout that scales with the screen size, don't use pixels to specify sizes. Use instead the "dp" unit (or dip). This unit is density independent, so when you make your layout fit the emulator screen size perfectly, then Android will take care of scaling for you, and it'll work for screens as small as a cheap phone (320x240px) to screen as large as 10" tablets. You need of course to provide images in various resolutions, because image scaling always gets very bad very quickly.
From the official Android Developers website:
Defining layout dimensions with pixels is a problem because different screens have different pixel densities, so the same number of pixels may correspond to different physical sizes on different devices. Therefore, when specifying dimensions, always use either dp or sp units. A dp is a density-independent pixel that corresponds to the physical size of a pixel at 160 dpi. An sp is the same base unit, but is scaled by the user's preferred text size (it’s a scale-independent pixel), so you should use this measurement unit when defining text size (but never for layout sizes).
In the same page they show how to provide the images for the various screen densities:
http://developer.android.com/training/multiscreen/screendensities.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With