安卓界面布局介绍

线性布局:LinerLayout

表格布局:TableLayout

相对布局:RelativeLayout

绝对布局:AbsoluteLayout

帧 布 局:FrameLayout

一、线性布局(LinearLayout) :线性布局是程序中最常见的一种布局方式,里面可以放多个控件线性布局通过android:orientation属性可以设置线性布局的方向,分为水平线性布局和垂直线性布局两种。该布局中组件会依次排列,且线性布局不会自动换行,组件会一个一个的排列到后头,超出边界的组件将不会被显示出来

在layout文件夹中的.xml文件里输入下面代码:

   <?xml version="1.0" encoding="utf-8"?>  

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  

    android:layout_width="fill_parent"  

    android:layout_height="fill_parent"  

    android:orientation="vertical" >  

    <!-- 最上面的两个按钮 -->  

    <LinearLayout  

        android:layout_width="fill_parent"  

        android:layout_height="fill_parent"  

        android:layout_weight="1"  

        android:orientation="horizontal" >  

        <!-- 同一层次的三个LinearLayoutlayout_weight都设置为1,每一个都占据三分之一的空间 -->  

        <LinearLayout  

            android:layout_width="fill_parent"  

            android:layout_height="fill_parent"  

            android:layout_weight="1"  

            android:orientation="vertical" >  

            <Button  

                android:layout_width="wrap_content"  

                android:layout_height="wrap_content"  

                android:layout_gravity="left"  

                android:text="左上按钮" />  

            <!-- 因为外层的LinearLayout定义为垂直布局,这里定义为在Layout里面靠左显示,所以就显示在左上角 -->  

        </LinearLayout>  

        <LinearLayout  

            android:layout_width="fill_parent"  

            android:layout_height="fill_parent"  

            android:layout_weight="1"  

            android:orientation="vertical" >  

            <Button  

                android:layout_width="wrap_content"  

                android:layout_height="wrap_content"  

                android:layout_gravity="right"  

                android:text="右上按钮" />  

        </LinearLayout>  

    </LinearLayout>  

    <!-- 中心的按钮 -->  

    <LinearLayout  

        android:layout_width="fill_parent"  

        android:layout_height="fill_parent"  

        android:layout_weight="1"  

        android:gravity="center"  

        android:orientation="vertical" >  

        <!-- 同一层次的三个LinearLayoutlayout_weight都设置为1,每一个都占据三分之一的空间 -->  

        <Button  

            android:layout_width="wrap_content"  

            android:layout_height="wrap_content"  

            android:text="中心按钮" />  

    </LinearLayout>  

    <!-- 最下面的两个按钮 -->  

    <LinearLayout  

        android:layout_width="fill_parent"  

        android:layout_height="fill_parent"  

        android:layout_weight="1"  

        android:orientation="horizontal" >  

        <!-- 同一层次的三个LinearLayoutlayout_weight都设置为1,每一个都占据三分之一的空间 -->  

        <LinearLayout  

            android:layout_width="fill_parent"  

            android:layout_height="fill_parent"  

            android:layout_weight="1"  

            android:gravity=

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值