Android 的通体布局

Android 的整体布局

        在Android  里主要有五种布局方式:LinearLayout(线性布局)、FrameLayout(单帧布局)、RelativeLayout(相对布局)、AbsoluteLayout(绝对布局)、 TableLayout(表格布局)。  我所了解的布局方式只有LinearLayout(线性布局)和RelativeLayout(相对布局)两种。
        LinearLayout(线性布局)是按照水平方向(horizontal)和垂直方向(vertical)依次排列元素,每一个元素都位于前一个元素之后。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.surface.MainActivity"
    tools:ignore="MergeRootFrame"
    android:orientation="vertical" >
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        
        <Button 
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.20"
            android:onClick="found"
            android:text="@string/text_add" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.39"
            android:onClick="found"
            android:text="@string/pause" />

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.31"
            android:onClick="found"
            android:text="@string/resume" />

        <Button
            android:id="@+id/button4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.33"
            android:onClick="found"
            android:text="@string/stop" />

    </LinearLayout>
    
    <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="sssssssssss" />
    
</LinearLayout>

 

        整体上是垂直方向(vertical)布局,在设置按钮(Button)时插入水平方向(horizontal)布局。如下图:

            
Android  的通体布局
 
        元素属性android:layout_weight用于描述该元素在空间中所占的大小比例,如:这四个按钮(Button)在水平方向所占的大小比例。这个元素刚开始的时候不明白什么意思,最近才明白。