3.FrameLayout:帧布局

如同Flash或者photoshop中图层的概念,在上面的图层遮盖下面的图层,没被遮到的地方仍然显示出来。

右击res/layout,然后在弹出的菜单中选择new,然后选择Android Xml File,要新建FrameLayout布局文件,就选择FrameLayout作为其根节点即可。文件名为frame_layout.xml。

代码如下:

 <?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:src="@drawable/bg"

         android:layout_gravity="center"

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"/>

     <ImageView

         android:src="@drawable/hero"

         android:layout_width="wrap_content"

         android:layout_gravity="center"

         android:layout_height="wrap_content"/>

 </FrameLayout>

依次放置两个ImageView用于显示两张图片,第一张为背景图片,第二张为一个人物图片。

修改FirstActivity中setContentView(R.layout.frame_layout);

显示效果如下:

先添加的控件位于下面,后添加的控件位于上面。

4.AbsoluteLayout:绝对布局

根据绝对坐标位置进行布局,不灵活,故而很少使用。

eclipse中也提示:AbsoluteLayout is deprecated,即不建议使用绝对布局。

新建一个layout文件,名为absolute_layout.xml,代码入下:

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

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

     android:layout_width="match_parent"

     android:layout_height="match_parent" >

     <Button

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"

         android:layout_x="100dp"

         android:layout_y="100dp"

         android:text="aaaaaa"

         />

 </AbsoluteLayout>

修改FirstActivity中代码:setContentView(R.layout.absolute_layout);

显示如下:

属性:

android:layout_x 指定控件在父布局的x轴坐标

android:layout_y      指定控件在父布局的y轴坐标

5.TableLayout:表格布局

需要配合TableRow进行使用,也不是太常用。

在TableLayout中每加入一个TableRow子节点,就表示在表格中加入了一行,之后在TableRow中每加入一个控件,就表示加入了一列。注意TableRow单元行里的单元格的宽度小于默认的宽度时就不起作用,其默认是fill_parent,高度可以自定义大小。

如果直接在TableLayout中添加控件,那么该控件将会占用一行。

新建一个layout布局文件,名为table_layout.xml,代码如下:

 <?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"

     >

     <Button

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"

         android:text="aaaaaa"

         />

     <TableRow >

         <Button

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"

         android:text="bbbbbb"

         />

     <Button

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"

         android:text="cccccc"

         />

      <Button

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"

         android:text="bbbbbb"

         />

     <Button

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"

         android:text="cccccc"

         />

      <Button

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"

         android:text="bbbbbb"

         />

     <Button

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"

         android:text="cccccc"

         />

     </TableRow>

    <TableRow >

         <Button

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"

         android:text="dddddd"

         />

     </TableRow>

     <Button

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"

         android:text="eeeeee"

         />

 </TableLayout>

修改setContentView(R.layout.table_layout);

显示效果如下:

第0行一个按钮aaaaaa

第1行6个按钮,但是父控件宽度有限,只显示了5个

第2行一个TableRow,里面加了一个按钮dddddd

第3行也是一个按钮eeeeee

主要属性:

android:shrinkColumns         设置收缩的列,其值为要收缩的列的索引,从0开始,多个时用逗号分隔。

如:android:shrinkColumns="0,2",表示第0和第2列收缩,显示效果如下:

可以看出没有放在TableRow中的行没有被收缩。

android:stretchColumns        设置拉伸的列,其值为要收缩的列的索引,从0开始,多个时用逗号分隔。如上显示中第1行有6个按钮,父容器宽度不够用,此时拉伸任何一列都不会有效果。若第1行只有两个按钮,此时,设置android:stretchColumns="1",则会把第1列拉伸,充满父容器剩下的空间。显示效果如下:

android:collapseColumns       设置要隐藏的列,这里的隐藏于visibility设置为gone效果相同的。隐藏之后不占用父容器的空间。

如:android:collapseColumns="1,3,5",则第一行6个按钮,只剩下3个bbbbbb

6.GridLayout:网格布局

Android4.0中新增的布局管理器。因此,在android4.0之后的版本才可以直接使用。

新建项目设置最小SDK为14,其他也要高于14。

新建一个layout文件,名为grid_layout.xml,代码如下:

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

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

     android:layout_width="match_parent"

     android:layout_height="match_parent"

     android:columnCount="5"

     android:rowCount="4">

     <Button

         android:layout_row="0"

         android:text="aaaaaa"

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"/>

     <Button

         android:layout_row="1"

         android:layout_column="0"

         android:text="bbbbbb"

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"/>

     <Button

         android:layout_row="2"

         android:layout_column="2"

         android:text="cccccc"

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"/>

     <Button

         android:layout_row="3"

         android:layout_column="1"

         android:text="dddddd"

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"/>

 </GridLayout>

显示效果如下:

整个布局被分为4行5列。

主要属性:

android:columnCount 设置GridLayout的列数

android:rowCount设置GridLayou的行数

每个添加到GridLayout中的子控件都可以设置如下属性:

android:layout_row  设置该元素所在行,从0开始

android:layout_column  设置该元素所在列,从0开始

android:layout_rowSpan  设置该元素所跨的行数

android:layout_columnSpan  设置该元素所跨的列数。

android菜鸟学习笔记7----android布局(二)的更多相关文章

  1. android菜鸟学习笔记13----Android控件(二) 自定义控件简单示例

    有时候,可能觉得系统提供的控件太丑,就会需要自定义控件来实现自己想要的效果. 以下主要参考<第一行代码> 1.自定义一个标题栏: 系统自带的标题栏很丑,且没什么大的作用,所以我们之前会在o ...

  2. android菜鸟学习笔记25----与服务器端交互(二)解析服务端返回的json数据及使用一个开源组件请求服务端数据

    补充:关于PHP服务端可能出现的问题: 如果你刚好也像我一样,用php实现的服务端程序,采用的是apache服务器,那么虚拟主机的配置可能会影响到android应用的调试!! 在android应用中访 ...

  3. android菜鸟学习笔记18----Android数据存储(二)SharedPreferences

    数据存储的方式,有比直接文件读写更加简便的方式,那就是操作SharedPreferences. SharedPreferences一般用于存储用户的偏好设定,暂时不支持多进程操作. SharedPre ...

  4. Java菜鸟学习笔记--数组篇(三):二维数组

    定义 //1.二维数组的定义 //2.二维数组的内存空间 //3.不规则数组 package me.array; public class Array2Demo{ public static void ...

  5. android菜鸟学习笔记31----Android使用百度地图API(二)获取地理位置及地图控制器的简单使用

    1.获取当前地理位置: Android中提供了一个LocationManager的类,用于管理地理位置.不能通过构造函数获取该类的实例,而是通过Context的getSystemService(): ...

  6. android菜鸟学习笔记9----Activity(二)

    关于Activity的生命周期: 下面是Activity整个生命周期中,状态发生变化时所回调的方法,它们对应着Activity完整的生命过程. void  onCreate(Bundle savedI ...

  7. android菜鸟学习笔记30----Android使用百度地图API(一)准备工作及在应用中显示地图

    1.准备工作: 百度地图API是免费开放的,但是需要申请API Key: 1)先注册一个百度开发者帐号 2)进入百度开放服务平台http://developer.baidu.com/ 3)进入LBS云 ...

  8. android菜鸟学习笔记29----Android应用向用户发送提示信息的方式总结

    常见的向用户发送提示信息的方式有3种,分别为: 1)发送Toast信息 2)弹出对话框 3)发送通知 总结如下: 方式1:发送Toast信息: 这种方式最简单,在之前的学习中多次使用过.Toast是在 ...

  9. android菜鸟学习笔记24----与服务器端交互(一)使用HttpURLConnection和HttpClient请求服务端数据

    主要是基于HTTP协议与服务端进行交互. 涉及到的类和接口有:URL.HttpURLConnection.HttpClient等 URL: 使用一个String类型的url构造一个URL对象,如: U ...

随机推荐

  1. 729 - The Hamming Distance Problem

      // 题意: // 输入两个整数N, H,按照字典序输出所有长度为N,恰好包含H个1的01串 // 规模:1<=H<=N<=16 // 算法A:2^N枚举,输出1的个数为H的.采 ...

  2. iOS设置某个界面强制横屏,进入就横屏

    最近有一个项目,例如:A界面跳转到B界面,A界面是竖屏的,B界面进入就要横屏. 花了半天的时间在网上搜索解决方案,有些论坛的大牛也就贴两行代码,具体实现也没有,对我们这种菜鸟造成一万点真实伤害.为了避 ...

  3. SCCM 2007 R2部署、操作详解系列之概念

    站点类型 在安装站点时,您决定它将是主站点还是辅助站点.然后,在安装其他站点时,您可以选择将其安排到层次结构关系中,以便父站点管理子站点,中央站点收集所有站点信息,从而进行集中式管理.也可以根据业务和 ...

  4. jeecg团队招新人(5人)

    jeecg团队招新人(5人) http://www.jeecg.org/forum.php? mod=viewthread&tid=2046&page=1&extra=#pid ...

  5. Flex数据交互之Remoting[转]

    Flex数据交互之Remoting 一 前言 Flex数据交互常用的有三种方式:WebService.HttpService以及Remoting. WebService方式已在这篇文章中给出,这篇文章 ...

  6. iOS开发——动画编程Swift篇&(五)CAKeyframeAnimation

    CAKeyframeAnimation //CAKeyframeAnimation-关键针动画 @IBAction func cakFly() { let animation = CAKeyframe ...

  7. 把你的旧笔记本变成 Chromebook

    导读 Linux 之年就在眼前.根据报道,Google 在 2016 年第一季度卖出了比苹果卖出的 Macbook 更多的 Chromebook.并且,Chromebook 即将变得更加激动人心.在 ...

  8. 实例讲解Linux系统中硬链接与软链接的创建

    导读 Linux链接分两种,一种被称为硬链接(Hard Link),另一种被称为符号链接(Symbolic Link).默认情况下,ln命令产生硬链接.硬链接与软链接的区别从根本上要从Inode节点说 ...

  9. View Controller 视图管理总结

    View controller是iOS中顶层的视图载体和控制器,它需要对view负责,管理view的生命周期,相关处室话以及交互事件,除此以外还需要为view提供合适的数据,以供view使用. Vie ...

  10. 多线程和并发管理 .NET多线程服务

    线程相关静态变量 默认静态变量应用程序域所有线程可见.如果静态变量需要在线程间共享,同步访问也就必然了. 线程相关静态变量保证线程安全,同一时间只有一个线程可访问,且每个线程都有该静态变量的拷贝. p ...