Gravity and layout_gravity on Android
I know we can set the following value to the android:gravity
and android:layout_gravity
.
- 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
?
Android
- asked 9 years ago
- B Butts
2Answer
Their names should help you:
android:gravity
sets the gravity of the content of theView
its used on.android:layout_gravity
sets the gravity of theView
orLayout
in its parent.
And an example is here.
- answered 8 years ago
- G John
android:layout_gravity
is the Outside gravity of the View. That means, to specify the direction in which the View should touch it's parent's border.
android:gravity
is the Inside gravity of that View. This means, in which direction it's contents should align.
HTML/CSS Equivalents:
android:layout_gravity
= float
in CSS
android:gravity
= text-align
in CSS
Easy trick to remember: Take "layout-gravity" as "Lay-outside-gravity"
- answered 8 years ago
- Sunny Solu
Your Answer