线性布局
LinearLayout是一种视图组,负责将视图水平或垂直保存在其中。这是一种布局,其中可以水平或垂直排列组。
示例图:
句法:
XML
XML
XML
XML
相对布局
RelativeLayout是一种布局,我们可以在其中根据其他视图/小部件的位置排列视图/小部件。它独立于水平和垂直视图,我们可以根据一次满足的要求进行排列。
示例图:
句法:
XML格式
LinearLayout和RelativeLayout之间的区别
LinearLayout |
RelativeLayout |
---|---|
We can adjust views and widgets linearly i.e. Horizontally and vertically. | We can adjust views and widgets according to one’s satisfaction. |
layout_weight attribute in the linear layout is used to specify the equal or specific size to the particular widget and view by using the following attribute. android:layout_weight = ‘0’ Here Weight is specified as 0 in order to give equal size or space to each view or widget. |
Various attributes like: layout_toRightOf, layout_toLeftOf, layout_below, layout_alignParentTop, layout_top, layout_alignParentLeft, layout_alignParentRight are used to specify the position of each view and widget. |
It is useful when we arrange views in a linear fashion | It is useful when we arrange views in a relative fashion. |
Syntax: |
Syntax: |
Example: In various Apps, LinearLayout is mainly applicable in the SignUp screen where Name, Email, Phone Number, Submit, etc. are arranged in a linear fashion. | Example: In Google Play Store, when we open the app, the games, books, movies, and App’s sections all are arranges in Relative Layout Fashion. |
LinearLayout is less used as compared to RelativeLayout. | RelativeLayout is used more in applications. |
We can use LinearLayout inside RelativeLayout. | We can also use RelativeLayout as a Child of LinearLayout. |
程序介绍LinearLayout
XML格式
输出:
程序说明RelativeLayout
XML格式
输出:
想要一个节奏更快,更具竞争性的环境来学习Android的基础知识吗?
单击此处前往由我们的专家精心策划的指南,以使您立即做好行业准备!