I know we can set the following values to the android:gravity
and android:layout_gravity
properties:
center
center_vertical
center_horizontal
, etc.
But I am confused regarding both of these.
What is the difference between the usage of android:gravity
and android:layout_gravity
?
The difference
android:layout_gravity
is the Outside gravity of the View. Specifies the direction in which the View should touch its parent's border.android:gravity
is the Inside gravity of that View. Specifies in which direction its contents should align.HTML/CSS Equivalents
Easy trick to help you remember
Take
layout-gravity
as "Lay-outside-gravity".An easy trick to remember this is gravity applies to us inside earth. So,
android:gravity
is for inside the view.Rememeber the out in layout_gravity which would help you to remember that
android:layout_gravity
would refer to outside the view