Android的布局方式

1.LinearLayout(线性布局)
  android:orientation="vertical" //布局
  android:layout_width="wrap_content" //控件宽度
  android:layout_height="fill_parent" //控件高度
  android:layout_weight //可以指定每个控件所占的比例
  注意:"vertical":垂直布局 "horizontal":水平布局
      wrap_content:宽度/高度和内容的宽度/高度相同
      fill_parent:宽度/高度是整个父组件的宽度和高度

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:orientation="vertical"
 4     android:layout_width="fill_parent" 
 5     android:layout_height="fill_parent" 
 6     >
 7        <TextView
 8             android:id="@+id/ete1"
 9            android:layout_width="100px" 
10             android:layout_height="100px" 
11             android:background="#00FF00"
12       />
13         <TextView
14             android:id="@+id/bte1"
15           android:layout_width="80px" 
16         android:layout_height="80px" 
17          android:background="#0000FF"
18      />
19       <TextView
20           android:id="@+id/tve1"
21         android:layout_width="60px" 
22         android:layout_height="60px" 
23            android:background="#FF0000"
24       />
25 </LinearLayout>
代码示例

2.FrameLayout(帧布局)
    叠加效果

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <!-- "vertical":垂直布局     "horizontal":水平布局 -->
 3 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 4     android:orientation="horizontal"
 5     android:layout_width="fill_parent"
 6     android:layout_height="fill_parent"
 7     >
 8   <TextView
 9           android:layout_width="100px"
10         android:layout_height="100px"
11         android:background="#FF0000"
12   />
13   <TextView
14           android:layout_width="80px"
15         android:layout_height="80px"
16         android:background="#00FF00"
17   />
18    <TextView
19           android:layout_width="60px"
20         android:layout_height="60px"
21         android:background="#0000FF"
22   />
23 </FrameLayout>
代码示例

3.Relativelayout(相对布局)
  android:layout_below //在某个组件的下面
  android:layout_toLeftOf //在某个组件的左边
  android:layout_toRinghtOf //在某个组件的右边
  android:layout_alignTop //在某个组件上对齐
  android:layout_alignBottom //在某个组件下对齐
  android:layout_alignLeft //在某个组件左对齐
  android:layout_alignRight //在某个组件右对齐

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:orientation="vertical"
 4     android:layout_width="fill_parent"
 5     android:layout_height="fill_parent"
 6     >
 7        <TextView
 8            android:id="@+id/tvr1"
 9           android:layout_width="100px"
10         android:layout_height="100px"
11         android:background="#FF0000"
12       />
13         <TextView
14             android:id="@+id/tvr2"
15           android:layout_width="80px"
16         android:layout_height="80px"
17         android:background="#00FF00"
18         android:layout_below="@+id/tvr1"
19          />
20       <TextView
21           android:id="@+id/tvr3"
22         android:layout_width="60px"
23           android:layout_height="60px"
24            android:background="#0000FF"
25            android:layout_alignRight="@+id/tvr1"
26       />
27 </RelativeLayout>
代码示例

4.TableLayout(表格布局)
  注意:表格布局的组件要放在TableRow中

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:orientation="vertical"
 4     android:layout_width="fill_parent"
 5     android:layout_height="fill_parent"
 6     >
 7 
 8     <TableRow>
 9         <TextView
10               android:layout_width="100px"
11             android:layout_height="100px"
12             android:background="#FF0000"
13           />
14     </TableRow>
15     <TableRow>
16          <TextView
17               android:layout_width="80px"
18             android:layout_height="80px"
19             android:background="#00FF00"
20           />
21           <TextView
22             android:layout_width="60px"
23               android:layout_height="60px"
24                android:background="#0000FF"
25           />
26     </TableRow>
27 </TableLayout>
代码示例

5.AbsoluteLayout(绝对布局)
  android:layout_x="80px" //x轴坐标值
  android:layout_y="20px" //y轴坐标值

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:orientation="vertical"
 4     android:layout_width="fill_parent"
 5     android:layout_height="fill_parent"
 6     >
 7        <TextView
 8            android:id="@+id/tvr1"
 9           android:layout_width="100px"
10         android:layout_height="100px"
11         android:background="#FF0000"
12       />
13         <TextView
14             android:layout_x="60px"
15             android:layout_y="10px"
16             android:id="@+id/tvr2"
17           android:layout_width="80px"
18         android:layout_height="80px"
19         android:background="#00FF00"
20         android:layout_below="@+id/tvr1"
21          />
22       <TextView
23           android:layout_x="80px"
24             android:layout_y="20px"
25           android:id="@+id/tvr3"
26         android:layout_width="60px"
27           android:layout_height="60px"
28            android:background="#0000FF"
29            android:layout_alignRight="@+id/tvr1"
30       />
31 </AbsoluteLayout>
代码示例
原文地址:https://www.cnblogs.com/yang82/p/6880087.html