Android中的gravity和layout_gravity有什么区别?
问题描述:
我知道我们可以为 android:gravity
和 android:layout_gravity
属性设置以下值:
I know we can set the following values to the android:gravity
and android:layout_gravity
properties:
-
center
-
center_vertical
-
center_horizontal
等
center
center_vertical
-
center_horizontal
, etc.
但是我对这两者感到困惑.
But I am confused regarding both of these.
android:gravity
和android:layout_gravity
的用法有什么区别?
What is the difference between the usage of android:gravity
and android:layout_gravity
?
答
他们的名字应该可以帮助您:
Their names should help you:
-
android:gravity
设置所使用的View
的内容(即其子视图)的重力. -
android:layout_gravity
设置View
或Layout
相对于其父级的重力.
-
android:gravity
sets the gravity of the contents (i.e. its subviews) of theView
it's used on. -
android:layout_gravity
sets the gravity of theView
orLayout
relative to its parent.
例如此处.