其他分享
首页 > 其他分享> > Android五大布局:FrameLayout、LinearLayout、AbsoluteLayout、RelativeLayout和TableLayout

Android五大布局:FrameLayout、LinearLayout、AbsoluteLayout、RelativeLayout和TableLayout

作者:互联网

Android SDK 定义了多种布局方式以方便用户设计 UI。各种布局方式均为 ViewGroup 类的子类,结构如图 1 所示。

Android SDK布局方式结构图
图 1  Android SDK 布局方式结构图
 

以下将对 FrameLayout(单帧布局)、LinearLayout(线性布局)、AbsoluteLayout(绝对布局)、RelativeLayout(相对布局)和TableLayout(表格布局)进行简单的介绍。

LinearLayout(线性布局)

实例 LinearLayoutDemo 演示了 LinearLayout 布局的使用方法,效果如下图所示。

 

 

      

         

 

 

 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="match_parent"
 5     android:layout_height="match_parent">
 6 
 7     <Button
 8         android:id="@+id/button7"
 9         android:layout_width="wrap_content"
10         android:layout_height="wrap_content"
11         android:text="Button" />
12 
13     <Button
14         android:id="@+id/button8"
15         android:layout_width="wrap_content"
16         android:layout_height="wrap_content"
17         android:text="Button" />
18 
19     <Button
20         android:id="@+id/button10"
21         android:layout_width="wrap_content"
22         android:layout_height="wrap_content"
23         android:text="Button" />
24 </LinearLayout>

 

 

 

 

 

将源代码改为如下:

 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:gravity="center"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent">
 7 
 8     <Button
 9         android:id="@+id/button7"
10         android:layout_weight="1"
11         android:layout_width="wrap_content"
12         android:layout_height="0dp"
13         android:text="Button" />
14 
15     <Button
16         android:id="@+id/button8"
17         android:layout_weight="1"
18         android:layout_width="wrap_content"
19         android:layout_height="0dp"
20         android:text="Button" />
21 
22     <Button
23         android:id="@+id/button10"
24         android:layout_weight="1"
25         android:layout_width="wrap_content"
26         android:layout_height="0dp"
27         android:text="Button" />
28 </LinearLayout>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

标签:控件,RelativeLayout,weight,布局,TableLayout,FrameLayout,layout,android,LinearLayout
来源: https://www.cnblogs.com/gh110/p/12489701.html