I know we can set the following values to the android:gravity
and android:layout_gravity
properties:
android:gravity
-> Sets the gravity of the content of the View its used on.
android:layout_gravity
-> Sets the gravity of it's Parent's view or Layout
android:gravity
is used to specify how to place the content of the object within the object itself. In another word, android:gravity is used to specify the gravity of the content of the view.
android:layout_gravity
is an attribution the child can supply to its parent, to specify the gravity the view within its parents.
For more details you can visit
http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html
android:gravity
is used to adjust for content of the view relative to its specify position (allocated area). android:gravity="left"
would not do anything if layout_width
is equal to the "wrap_content"
android:layout_gravity
is used for view itself relative to the parent or layout file.
The basic difference between the two is that-
android:gravity is used for child elements of the view.
android:layout_gravity is used for this element with respect to parent view.
From what I can gather layout_gravity is the gravity of that view inside its parent, and gravity is the gravity of the children inside that view.
I think this is right but the best way to find out is to play around.
Gravity is used to set text alignment in views but layout_gravity is use to set views it self. Lets take an example if you want to align text written in editText then use gravity and you want align this editText or any button or any view then use layout_gravity, So its very simple.