布局分4种:

1. LinearLayout (线性布局)

file:///H:/tool/01/Android/android-sdk-windows/docs/guide/topics/ui/layout/linear.html

事例代码:

2. RelativeLayout (相对布局)

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="fill_parent"
  4. android:layout_height="wrap_content"
  5. android:padding="10dp"
  6. >
  7.  
  8. <TextView
  9. android:id="@+id/numbeLabel"
  10. android:layout_width="fill_parent"
  11. android:layout_height="wrap_content"
  12. android:text="@string/number" />
  13.  
  14. <EditText
  15. android:id="@+id/number2"
  16. android:layout_width="fill_parent"
  17. android:layout_height="wrap_content"
  18. android:hint="@null"
  19. android:layout_below="@id/numbeLabel" //这里表示这个控件显示在idnumberLabel这个控件下面
  20. />
  21.  
  22. <Button
  23. android:id="@+id/ok"
  24. android:text="@string/ok"
  25. android:layout_width="wrap_content"
  26. android:layout_height="wrap_content"
  27. android:layout_below="@id/number2"
  28. android:layout_alignParentRight="true" //这里表示这个控件在父对象里面是居右显示
  29. android:layout_marginLeft="10px" //这里表示这个控件跟左边这个控制的间距是10像素
  30. />
  31.  
  32. <Button
  33. android:text="@string/cancel"
  34. android:layout_width="wrap_content"
  35. android:layout_height="wrap_content"
  36. android:layout_toLeftOf="@id/ok" //表示显示在ok这个按钮左边
  37. android:layout_alignTop="@id/ok" //表示与ok这个按钮,顶对齐
  38. />
  39.  
  40. </RelativeLayout>

3. TableLayout (表格布局)

4. FrameLayout (帧布局)

就像gif图片一样,或者可以理解成层,可以叠加在一起

  1. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="fill_parent"
  3. android:layout_height="fill_parent" >
  4.  
  5. <ImageView
  6. android:layout_width="fill_parent"
  7. android:layout_height="fill_parent"
  8. android:src="@drawable/bofangtwo"
  9. android:contentDescription="@string/app_name"
  10. />
  11.  
  12. <ImageView
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. android:src="@drawable/bofang"
  16. android:contentDescription="@string/app_name"
  17. android:layout_gravity="center"
  18. />
  19. </FrameLayout>

注意:在写

  1. android:src="@drawable/bofang"的时候,注意图片后面的扩展名不要带,带上就会出错!
    bofang.pngbofangtwo.jpg复制到res中的drawable-hdpi

Android 学习第14课,Android 布局的更多相关文章

  1. android学习点滴一:android环境的搭建

    东一点西一点,很多时间都浪费了.是该系统性的做好自己的东西了. <android学习点滴一:android环境的搭建> [环境变量]变量名:JAVA_HOME变量值:C:\Java\jdk ...

  2. Android学习笔记(九)——布局和控件的自定义

    //此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! View是 Android中一种最基本的 UI组件,它可以在屏幕上绘制一块矩形区域,并能响应这块区域的各种事件 ...

  3. Android 学习第13课,android 实现发送短信的功能

    1. 界面布局 界面代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ...

  4. Android 学习第11课,android 实现拨打电话的功能

    1. 先布局界面,界面采用线性垂直方式来布局 在layout 界面文件中 activity_main.xml 中 <LinearLayout xmlns:android="http:/ ...

  5. android学习笔记14——GridView、ImageSwitcher

    GridView--网格视图.ImageSwitcher--图像切换器 ==> GridView,用于在界面上按行.列的分布形式显示多个组件:GridView和ListView父类相同——Abs ...

  6. Android学习手记(5) 基本UI布局

    1.View和ViewGroup Activity是Android应用程序的基本管理单元,Android的每一个窗口都是通过一个Activity来定义的,但是Activity并不能直接用来显示窗口.我 ...

  7. Android学习笔记六:六大布局

    六大界面布局方式包括: 线性布局(LinearLayout).帧布局(FrameLayout).表格布局(TableLayout).相对布局(RelativeLayout).绝对布局(Absolute ...

  8. Android学习笔记_3_四种布局

    Android布局是应用界面开发的重要一环,在Android中,共有四种布局方式, 分别是:FrameLayout( 帧布局 ).LinearLayout (线性布局).TableLayout(表格布 ...

  9. Android 学习第7课,java android project 项目文档结构

    src: 主要存放java源文件 gen:用于存放由开发工具自动生成的内容 R.java(很重要),用于登记各种资源的ID,编译器在你放入资源于自动生成的,程序员不需要自己去修改,是不能自己修改的 往 ...

随机推荐

  1. win7/8/10安装过程中将动态磁盘转为basic

    在分区界面运行Shift+F10 在命令窗口运行Diskpart list diskpart select disk n(n为磁盘号) clean convert xxx PS:xxx代表要转换的结果 ...

  2. C++ 读取txt文本内容,并将结果保存到新文本

    循序渐进学习读文件 // readFile.cpp : 定义控制台应用程序的入口点. #include "stdafx.h" #include <iostream> # ...

  3. 高性能Web服务器Nginx的配置与部署研究系列(1)-- 入门 hello work

    简介: Nginx 是一个基于 BSD-like 协议.开源.高性能.轻量级的HTTP服务器.反向代理服务器以及电子邮件(SMTP.POP3.IMAP)服务器.Nginx 是由一个俄罗斯的名叫“Igo ...

  4. CALayer 3 详解 -----转自李明杰

    CALayer3-层的属性   本文目录 一.隐式动画属性 二.position和anchorPoint 回到顶部 一.隐式动画属性 * 在前面几讲中已经提到,每一个UIView内部都默认关联着一个C ...

  5. stm8s103串口

    #include "uart.h" #define UART2#define uart_115200 1 void Init_UART2(void){#ifdef UART2    ...

  6. 写程序该选Mac 还是PC ?(转)

    原文链接:http://gogojimmy.net/2012/04/07/why-programmer-should-use-mac/ 序 一个竞争的市场,就会有对立的产生,这世界存在着很多不同的领域 ...

  7. C语言经典例题100

    C语言经典例题100 来源 http://www.fishc.com 适合初学者 ----------------------------------------------------------- ...

  8. 最强密码 (百度之星复赛 T5)

    题目大意: 给出一个字符串A,要求最短的字符串B,B不是A的子序列. 求最短长度 和 最短的字符串个数    |A|<=105. 题解: 1.比赛的时候没有想出来,时隔一个多月又看到了这道题,虽 ...

  9. 简单研究Loader笔记

    2015-11-11 18:25:34 1. Loader是什么? /** * Static library support version of the framework's {@link and ...

  10. 【PHP】分页条函数封装

    这两天在学习PHP 想做一个前端后台都包含的网站 看了一些视频发现大牛们都是将封装起来实现代码的重用性 本人技拙也写了个分页条函数的封装 分页条在用PHP网站开发中十分常用 通过封装代码来提高网站开发 ...