Paresh Mayani Paresh Mayani - 2 months ago 9
Android Question

Gravity and layout_gravity on Android

I know we can set the following value to the

android:gravity
and
android:layout_gravity
.


  1. center

  2. center_vertical

  3. 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
?

Answer

Their names should help you:

  • android:gravity sets the gravity of the content of the View its used on.
  • android:layout_gravity sets the gravity of the View or Layout in its parent.

And an example is here.

Comments