Android界面的布局主要有四种,分别为RelativeLayout、LinearLayout、TableLayout、FrameLayout,接下来分别介绍这些布局如何使用(为了简单起见,接下来的介绍工作中,我分别附上布局文件的代码以及效果图,供大家参考)

一:RelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background" >
   
    <TextView
        android:id="@+id/background_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Type here" />
   
    <EditText
        android:id="@+id/background_edittext1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/background_textview"
        android:background="@android:drawable/editbox_background"/>
   
    <Button
        android:id="@+id/background_button_ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/background_edittext1"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="10px"
        android:text="Ok"/>
   
    <Button
        android:id="@+id/background_button_cancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/background_edittext1"
        android:layout_toLeftOf="@id/background_button_ok"
        android:layout_alignTop="@id/background_button_ok"
        android:text="Cancel"/>

</RelativeLayout>

效果图:

 

二:嵌套布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/background" >
   
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:background="@drawable/background_blue">
       
        <TextView
            android:id="@+id/multilayout_textview1"
            android:layout_marginTop="15dp"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:textColor="@color/abc_search_url_text_holo"
            android:text="PhoneNumber:"/>
       
        <EditText
            android:id="@+id/multilayout_editText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:minLines="1"
            android:maxLines="1"
            android:layout_toRightOf="@id/multilayout_textview1"
            android:background="@android:drawable/editbox_background"
            android:layout_alignBottom="@id/multilayout_textview1"
            />
       
    </RelativeLayout>
   
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Please Input The Message To Send"/>
   
    <EditText
        android:id="@+id/multilayout_editText2"
        android:layout_width= "fill_parent"
        android:layout_height="wrap_content"
        android:minLines="3"
        android:maxLines="7"
        android:background="@android:drawable/editbox_background"/>

    <Button
        android:id="@+id/multilayout_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="    Send     " />

</LinearLayout>

效果图:

 

三:表格布局

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="1" >
   
    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="100dp">
        <TextView
            android:id="@+id/table_layout_textview1"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:text="电话号码:"/>
        <EditText
            android:id="@+id/table_layout_edittext1"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"/>
    </TableRow>
   
    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="200dp">
        <TextView
            android:id="@+id/table_layout_textview2"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:text="短信内容:"/>
        <EditText
            android:id="@+id/table_layout_edittext2"
            android:layout_width="wrap_content"
            android:layout_weight="1"
            android:minLines="3"
            android:maxLines="7"
            android:layout_height="fill_parent"/>
    </TableRow>
   
    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="50dp">
        <Button
            android:id="@+id/table_layout_button1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="发送"/>
    </TableRow>
   

</TableLayout>

效果图:

 

四:Frame布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
   
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/movie"/>
   
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/pause"
        android:layout_gravity="center"/>

</FrameLayout>

效果图:此布局为,第二张ImageView覆盖在第一张ImageView上面

 

 

注:以上布局有些简单,仅供以后忘记时参考

Android学习5—布局简介的更多相关文章

  1. android 学习 之 布局(上)

    学习安卓布局前,先了解三个属性值: 1.fill_parent: 设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间 2.match_parent: And ...

  2. android学习日记02--Activity简介

    一.Activity活动 学习Android,第一个都会接触Activity滴,Activity表示一个用户界面,是Android应用程序的入口,可以同时有多个界面,但只会显示栈顶的界面. Activ ...

  3. Android学习----五大布局

    1.LinearLayout 线性布局 android:orientation="horizontal" 制定线性布局的排列方式 水平 horizontal 垂直 vertical ...

  4. android 学习Layout布局的使用

    android 常用布局 LinearLayout(线性布局) 线性的 垂直的 水平的RelativeLaytout(相对布局) 最灵活的TableLayout(表格布局) 使用GridView代替A ...

  5. Android学习——LinearLayout布局实现居中、左对齐、右对齐

    android:orientation="vertical"表示该布局下的元素垂直排列: 在整体垂直排列的基础上想要实现内部水平排列,则在整体LinearLayout布局下再创建一 ...

  6. android学习笔记一——简介

    android 是由Andy Rubin创立的一个手机操作系统,后被google收购. google希望同各方共同建立一个标准化.开放式的移动电话软件平台,从而在移动产业内形成了一个开放式的操作平台. ...

  7. android学习日记18--Adapter简介

    一.Adapter 1.简述 最近学的GridView和Gallery 都有用到Adapter适配器,发现它貌似蛮重要的.专门上网搜了下有关Adapter的资料.android绝大多数应用是JAVA语 ...

  8. android 学习 之 布局(下)LinearLayout,RelativeLayout,TableLayout,FrameLayout

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

  9. 【ALearning】第四章 Android Layout组件布局(一)

    在本章中,我们将Android学习组件布局.在前面的章节,我们也开始使用LinearLayout布局.然后我们在布局文件更加具体的学习和理解,会. Android的界面是有布局和组件协同完毕的,布局好 ...

随机推荐

  1. JavaScript- The Good Parts Chapter 3 Objects

    Upon a homely object Love can wink.—William Shakespeare, The Two Gentlemen of Verona The simple type ...

  2. .NET程序集(Assembly)

    在.NET 中,新引入了一个程序集的概念,就是指经由编译器编译得到的,供CLR进一步编译执行的那个中间产物,在WINDOWS系统中,它一般表现为.dll,或者是.exe的格式,但是要注意,它们跟普通意 ...

  3. 【Apache开源软件基金会项目】

    因为想要继续巩固一下外语,并且扩展下java的知识面,翻译一下Apache软件基金会的各个项目是个不错的选择. 2014-10-19 1 [Apache .NET Ant Libary] .net A ...

  4. oracl使用DataBase Configuration Assistant创建、删除数据库

    原文:oracl使用DataBase Configuration Assistant创建.删除数据库 可以使用DataBase Configuration Assistant来创建一个心得数据库.Da ...

  5. ios的@property属性和@synthesize属性

    当你定义了一系列的变量时,需要写很多的getter和setter方法,而且它们的形式都是差不多的,,所以Xcode提供了@property 和@synthesize属性,@property用在 .h ...

  6. java15 IO装饰设计模式

    IO装饰设计模式:(IO中使用了装饰设计模式) 节点流可以直接从源读取数据,处理流就是对节点流的包装,这就是装饰,装饰就是对原有的流的性能的提升.比如买的车,马力不够,就进行装饰,使其马力增大. 装饰 ...

  7. Mac OS X 如何设置默认浏览器

    有时候我们不希望在 Mac 中点击任何连接都打开的是 Safari,这需要修改默认浏览器设置,在 Mac OS X 中如何设置默认浏览器呢? 打开 Safari 的偏好设置,在「通用」选项卡中有「默认 ...

  8. 【十分钟教会你汇编】MIPS编程入门(妈妈说标题要高大上,才会有人看>_<!)

    无意中找到一篇十分好用,而且篇幅也不是很大的入门教程,通篇阅后,再把“栗子”敲一遍,基本可以有一个比较理性的认识,从而方便更好地进一步深入学习. 废话不多说,上干货(英语好的直接跳过本人的渣翻译了哈— ...

  9. j2ee学习笔记 javascript 学习

    JavaScript 组成: ECMAScript + BOM + DOM Window对象是JS中的顶层对象 ECMAScript: 规定了一些语法,变量,for循环等等结构 BOM: Browse ...

  10. Android的Manifest配置文件介绍

    一.关于AndroidManifest.xml       AndroidManifest.xml 是每个android程序中必须的文件.它位于整个项目的根目录,描述了package中暴露的组件(ac ...