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
等
但我对这两者感到困惑.
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.
一个例子是这里.