What is the difference between gravity and layout_gravity in android?


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

Here is the defination of gravity  Standard constants and tools for placing an object within a potentially larger container. in developer.android.com and more http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html

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"

below examples show difference between layout:gravity and gravity,may be help you. http://sandipchitale.blogspot.com/2010/05/linearlayout-gravity-and-layoutgravity.html


Happy Coding !!!
What is the difference between gravity and layout_gravity in android? What is the difference between gravity and layout_gravity in android? Reviewed by D Kshetri on 12:47 PM Rating: 5

No comments:

Powered by Blogger.