layout_gravity in Android XML

If the layout_gravity property is a mystery to you in android xml, i just figured out what it is. This tip will help you if you understand basic html.

<p align="right">Hello World</p>

As we can see, the align property will cause the browser to align the element to the right of it’s container element, which might be a div or a DOM or anything else.

Gravity works the opposite. If you set layout_gravity="left" then the element if aligned right. If you set it toright the element is aligned left. It’s just how gravity works. It’s a force that pushes the object towards the opposite side of it’s origin.

You can find more info about gravity here

Posted