Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you compare Android's box model to CSS's box model, I find Android's indeed easier to grasp, and of much lower complexity. You don't have those shenanigans like the padding getting added up to the element's width. IMHO, positioning logic (CSS: float/absolute/relative etc.) is very well and elegantly encapsulated in Android's layout components. While some things are hard to do in Android (like having a toolbar at the view's bottom and filling the rest with a list - but this also involves evil hackery in CSS), it's much more predictable than CSS.</p> <p>I would suggest that you read up on all layout components, as the box model is straightforward (margin, padding, width, height), and most of positioning and alignment is layout-component-specific (e.g., "gravity" in LinearLayout, "layout_above/below/toLeftOf/toRightOf" in RelativeLayout,...). </p> <p>BUT: I agree that a complete guide (+ good examples and analogies) on that topic would help novices to come to terms with Android layouts much quicker, since some in-depth info is only available as case-based code snippets (speaking only of the web, books surely do a better job).</p> <p>As a side-note on the box-model: One "peculiarity" I have stumbled upon is that <a href="http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch" rel="nofollow">9-patch-drawables</a> which are set as a background to an element affect the element's padding. If the box-padding of the 9-patch is not 0, the element's padding is set accordingly, if not overridden. This really bit me in the butt once.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload