Extended explanation of Android layout properties?

I am on a search to find out how to properly assemble components in Android. I am an experienced CSS / MXML developer, and it is very difficult for me to get a complete picture of the layout properties in Android components.

One thing: I'm not sure about the differences between the two:

  • layout_margin vs. padding
  • layout_gravity vs. gravity vs. ignoreGravity

Should you use one above the other with linear, tabular or relative layouts? An example of something that I would like to know is the total margin on the layout with the individual components related to the top / middle / bottom of the screen. Sdk docs are a good start, but they don’t show how everything works in different situations.

Any tips on where to go to explore a more complex / comprehensive layout design?

+8
android android-layout android-styles
source share
2 answers

Any attribute prefixed by layout_ is an attribute of LayoutParams . Although most of the attributes of the view are analyzed during the construction of the view by the view itself, LayoutParams are special arguments to the parent view that provide hints on how the parent should determine the size and position of the child view. Which LayoutParams are valid for the view depends entirely on the type of the parent view.

layout_margin is an instruction for a parent view that supports fields. It says: "Put this much space between me and other looks or the edge of the parent." A spacer is the space inside the edge of a view and its contents.

layout_gravity - gravity for one child inside his parent. gravity affects the contents of the displayed view.

Which one you use depends on the result you want to achieve. If you want the layout to have a fixed space between its edges and all the content, you want to fill. If you want to move the layout of your borders to a certain distance, you need fields. When you have layouts without a background set, the two can be visually equivalent. When you start creating sophisticated user interfaces, where layouts have backgrounds with 9 patches that visually group content, the differences become apparent.

+10
source share

enter image description here

I hope you see the difference between indentation and margin. The gasket is inside the interval, while the margin is outside the interval.

-one
source share

All Articles