3

I'm some what new to android and I'm really confused very much about the difference between parameters android:layout_gravity and android:gravity. So can someone please help me on using these. Thank you!

Jb Meris
  • 135
  • 2
  • 5
  • 17
Samantha Withanage
  • 3,811
  • 10
  • 30
  • 59

3 Answers3

3

android:layout_gravity is the gravity related to your whole Layout like LinearLayout,Relative layout and android:gravity is the gravity related to your particular view like Button,EditText..etc Hope this helps

Siddharth_Vyas
  • 9,972
  • 10
  • 39
  • 69
2

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.

go through this example

Avinash
  • 123
  • 1
  • 12
1

android:gravity applies graivity to the content of the view, while android:layout_gravity applies gravity to the view itself inside its parent.

For a button,layout_gravity will apply gravity to whole button whereas android:gravity will apply to its content that is text on Button etc.

Jigar Pandya
  • 2,129
  • 2
  • 17
  • 27