线性和相对布局有什么区别?

use*_*367 7 layout android

线性和相对布局有什么区别?

Dev*_*ath 13

LINEAR LAYOUT ::

  • 在线性布局中,如名称所示,所有元素都以线性方式显示
  • 水平或垂直此行为在android:orientation中设置,它是节点LinearLayout的属性.
  • 线性布局将每个孩子一个接一个地放在一条线上,水平或垂直.

点击这里---- for --- Android Docs线性布局参考

图示表示


RELATIVE LAYOUT::

  • 在相对布局中,每个元素相对于其他元素或父元素排列自身.
  • 在将视图添加到其他视图旁边时很有用
  • 使用相对布局,您可以为每个子项提供一个LayoutParam,它指定相对于父项或相对于其他子项的确切位置.
  • 视图在相对布局中相互叠加

点击这里---- for --- Android Docs参考相对布局

图示表示


优化 :: 看看优化布局层次结构

更少的观点,更好 ::

  1. The number one goal for your layouts should be using the fewest number of Views possible. The fewer Views you have to work with, the faster your application will run. Excessive nesting of Views further slows down your application.

  2. A RelativeLayout hierarchy will typically use fewer Views and have a flatter tree than a LinearLayout hierarchy. With LinearLayout, you must create a new LinearLayout every time you want to change the orientation of your views – creating additional Views and a more nested hierarchy. As a result, it is recommended that you first use RelativeLayout for any layout that has any complexity. There is a high probability you will reduce the number of Views – and the depth of your View tree – by doing so.


Vag*_*ant 9

线性布局将每个孩子一个接一个地放在一条线上,水平或垂直.使用相对布局,您可以为每个子项提供一个LayoutParam,它指定相对于父项或相对于其他子项的确切位置.