Summary of the differences of gravity layout_gravity padding and margin in Android

  • 2020-06-03 08:12:54
  • OfStack

1. Differences between gravity and layout_gravity


Property is the qualification to the view content. For example, text above button. You can set the text to the left, right and so on of view. That property does that.


Is used to set the position of the view relative to the parent view. For example, an button in linearlayout can be set by this property if you want to place the button to the left, right, etc.

So that explains what we have here, we have the outermost layout, and we have a couple of layouts inside, and if we want to have all of them at the bottom, we can set gravity= "botton" in the outermost layout property because gravity is what's inside.

2. Differences between padding and margin


Padding refers to the distance between the content in view and the view edge, similar to indent in the text


Represents the distance between the left edge of view and the left edge of parent view

margin1 describes location relationships between controls, while padding1 describes content and location relationships between controls.

Related articles: