What is the difference between linear and relative layout?

后端 未结 10 1653
無奈伤痛
無奈伤痛 2020-12-30 13:48

What is the difference between linear and relative layout?

相关标签:
10条回答
  • 2020-12-30 14:34

    From Android developer documentation: Common Layout Objects

    LinearLayout

    LinearLayout aligns all children in a single direction — vertically or horizontally, depending on how you define the orientation attribute.

    RelativeLayout

    RelativeLayout lets child views specify their position relative to the parent view or to each other (specified by ID)

    0 讨论(0)
  • 2020-12-30 14:35

    One of the characteristic feature of LinearLayout in Android is use of a property called Weight, which app can specify using android:layout_weight. This attribute assigns an "importance" value to a view in terms of how much space it should occupy on the screen.

    On the other hand, RelativeLayout do not support weight or in other words, RelativeLayout does not pay attention to android:layout_weight. That's a property of LinearLayout.LayoutParams, but not of RelativeLayout.LayoutParams.

    0 讨论(0)
  • 2020-12-30 14:38

    Linear layouts put every child, one after the other, in a line, either horizontally or vertically. With a relative layout you can give each child a LayoutParam that specifies exactly where is should go, relative to the parent or relative to other children.

    0 讨论(0)
  • 2020-12-30 14:40

    The following link should explain visually how the layouts work "Visually"
    http://www.droiddraw.org/
    Add some components to the window and mess with layouts to see what happens this is how I learned what each one does.

    0 讨论(0)
提交回复
热议问题