首页 文章

LinearLayout,RelativeLayout和AbsoluteLayout有什么区别?

提问于
浏览
159

我对LinearLayout,RelativeLayout和AbsoluteLayout之间的区别感到困惑 . 有人可以告诉我他们之间的确切差异吗?

7 回答

  • 76

    LinearLayout 表示您可以逐个对齐视图(垂直/水平) .

    RelativeLayout 表示基于其父母和其他观点的观点关系 .

    ConstraintLayout 类似于RelativeLayout,因为它使用关系来定位和调整小部件,但具有额外的灵活性,并且更容易在布局编辑器中使用 .

    WebView 加载html,静态或动态页面 .

    FrameLayout 将孩子一个装在另一个上面,就像一个框架内的卡片一样,我们可以将一个放在另一个上面或框架内的任何地方 .

    deprecated - AbsoluteLayout 表示您必须在视图所在的位置给出准确的位置 .

    有关更多信息,请查看此地址https://developer.android.com/guide/topics/ui/declaring-layout#CommonLayouts

  • 47

    FrameLayout :用作显示单个对象的视图框架的布局 .

    RelativeLayout :允许您指定子对象相对于彼此的位置(子B的左侧的子A)或父对象的位置(与父对象的顶部对齐) .

    LinearLayout :将子项组织为单个水平或垂直行的布局 .

    TableLayout :具有任意行数和列数的表格布局,每个单元格包含您选择的小部件 . 行调整大小以适合最大的列 . 单元格边框不可见 .

  • 2

    定义:

    enter image description here


    更多信息:

    FrameLayout ::
    enter image description here
    RelativeLayout ::
    enter image description here
    TableLayout ::
    enter image description here


    Note : - 绝对布局已被删除

    SourceAndroid Developers

  • 3

    1) FrameLayout - 框架布局 pins each child view within its frame . 默认位置是左上角,但您可以使用gravity属性来更改其位置 .

    添加多个子节点将每个新子节点堆叠在之前的子节点之上, ie with each new View potentially hiding the previous ones.

    2) LinearLayout - 线性布局以垂直或水平线对齐每个子视图 . 垂直布局具有一列视图,而水平布局具有一行视图 . 线性布局支持 weight attribute for each child View that can control the relative size of each child View within the available space.

    3) RelativeLayout - 相对布局允许您定义 positions of each child View relative to the othersscreen boundaries .

    4) GridLayout - 在 Android 4.0 (API level 14) 中引入,网格布局在一系列行和列中使用 rectangular grids to layout Views .

  • 9

    LinearLayout : 将子项组织为单个水平或垂直行的布局 . 如果窗口的长度超过屏幕的长度,它会创建一个滚动条 . 这意味着您可以逐个(垂直/水平)对齐视图 .

    RelativeLayout : 这使您可以指定子对象相对于彼此的位置(子B的左侧的子A)或父对象的位置(与父对象的顶部对齐) . 它基于其父母和其他观点的观点关系 .

    WebView : 加载html,静态或动态页面 .

    有关更多信息,请参阅此链接:http://developer.android.com/guide/topics/ui/layout-objects.html

  • 184

    LinearLayout - 在LinearLayout中,视图以垂直或水平方向组织 .

    RelativeLayout - RelativeLayout比LinearLayout更复杂,因此提供了许多功能 . 视图的名称相对于彼此放置 .

    FrameLayout - 它表现为单个对象,其子视图相互重叠 . FrameLayout采用最大子元素的大小 .

    Coordinator Layout - 这是Android支持库中引入的最强大的ViewGroup . 它表现为FrameLayout,并具有很多功能来协调其子视图 . 例如浮动按钮和快餐栏,具有可滚动视图的工具栏 .

  • 3

    这里有很棒的解释

    http://www.cuelogic.com/blog/using-framelayout-for-designing-xml-layouts-in-android/

    LinearLayout 水平或垂直排列元素(行与列) .

    RelativeLayout 是一个布局管理器,可帮助您根据某些规则排列UI元素 . 您可以指定以下内容:将此对齐到父项左边缘,将其放在此元素的左侧/右侧等 .

    AbsoluteLayout 用于绝对定位,即您可以指定视图应该到达的精确坐标 .

    FrameLayout 允许沿Z轴放置 . 也就是说,您可以将视图元素叠加在另一个之上 .

相关问题