【问题标题】: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


【解决方案1】:

android:gravity 设置其使用的View 内容的重力。
android:layout_gravity 设置其父级中ViewLayout 的重力。

查看https://stackoverflow.com/a/6819801/1434631

【讨论】:

  • 谢谢你。很有用。
【解决方案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:这将指定视图在其父布局中的位置,这意味着如果您的布局更大,则其中的视图将决定此视图将触及此布局的哪个边界。

    【讨论】:

      猜你喜欢
      • 2013-12-02
      • 1970-01-01
      • 2017-02-17
      • 2011-09-27
      • 2013-04-22
      • 2012-03-29
      • 1970-01-01
      • 1970-01-01
      • 2013-10-06
      相关资源
      最近更新 更多