【问题标题】:What is the difference between android:gravity and android:layout_gravity [duplicate]android:gravity 和 android:layout_gravity 有什么区别 [重复]
【发布时间】:2013-04-01 22:28:52
【问题描述】:
我正在开发一个简单的 android 应用程序,我需要在特定位置对齐一些视图,但不使用填充或常量整数值作为大小,我想使用重力属性来做到这一点,谁能告诉我什么是重力属性,android:gravity 和 android:layout_gravity 属性有什么区别。
提前致谢。
【问题讨论】:
标签:
android
android-layout
【解决方案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.
【解决方案3】:
Gravity: 将指定视图内容的下车位置,这意味着如果您有一个 TextView 并且它的两个维度的参数都不是 wrap_content,那么 Gravity 将确定这段文字将触及哪个边界。
Layout_Gravitiy:这将指定视图在其父布局中的位置,这意味着如果您的布局更大,则其中的视图将决定此视图将触及此布局的哪个边界。