基础学习总结(二)

用户界面View
五大布局:
1、LinearLayout 线性布局
2、RelativeLayout 相对布局
5、AbsoluteLayout 绝对布局
4、TableLayout 表格布局
3、FrameLayout 祯布局

1.LinearLayout线性布局
android:orientation="horizontal" 制定线性布局的排列方式
水平 horizontal
垂直 vertical
gravity 控制当前控件内容显示区域
layout_gravity 当前控件在父元素的位置
Layout_weightSum
Layout_weight 额外空间分配(权重)

android:visibility="invisible" 控制布局是否显示
显示 visible
不显示,但占空间 invisible
隐藏 gone
2.RelativeLayout相对布局
android:layout_toRightOf 在指定控件的右边
android:layout_toLeftOf 在指定控件的左边
android:layout_above 在指定控件的上边
android:layout_below 在指定控件的下边
android:layout_alignBaseline 跟指定控件水平对齐
android:layout_alignLeft 跟指定控件左对齐
android:layout_alignRight 跟指定控件右对齐
android:layout_alignTop 跟指定控件顶部对齐
android:layout_alignBottom 跟指定控件底部对齐
android:layout_alignParentLeft 是否跟父布局左对齐
android:layout_alignParentTop 是否跟父布局顶部对齐
android:layout_alignParentRight 是否跟父布局右对齐
android:layout_alignParentBottom 是否跟父布局底部对齐
android:layout_centerVertical 在父布局中垂直居中
android:layout_centerHorizontal 在父布局中水平居中
android:layout_centerInParent 在父布局中居中

<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="进攻" />
<!-- centerHorizontal水平居中 -->

<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="左勾拳" />
<!-- centerVertical 垂直居中 -->

<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:text="右勾拳" />
<!-- 水平靠右 -->

<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="下蹲" />
<!-- alignParentBottom 水平底部 -->

<Button android:id="@+id/btn_bisha" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="必杀" />
<!-- centerInParent居正中 -->

<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/btn_bisha"
android:layout_alignTop="@+id/btn_bisha"
android:text="左" />
<!-- toLeftOf="@+id/btn_bisha"在指定控件的左边
alignTop="@+id/btn_bisha"与指定控件的上边线对齐
-->

<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="@+id/btn_bisha"
android:text="上" />
<!-- above="@+id/btn_bisha"在指定控件的顶部 -->

<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/btn_bisha"
android:layout_alignBaseline="@+id/btn_bisha"
android:text="右" />
<!-- alignBaseline="@+id/btn_bisha"与指定控件同一行 -->

<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_bisha"
android:layout_centerHorizontal="true"
android:text="下" />
<!-- below="@+id/btn_bisha"在指定控件底部 -->

3.FrameLayout帧布局:每次添加的控件都显示在最上面,最后显示在界面上的是最后添加的一个控件

 1 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     android:layout_width="match_parent"
 3     android:layout_height="match_parent" >
 4
 5     <Button
 6         android:layout_width="300px"
 7         android:layout_height="300px"
 8         android:layout_gravity="center"
 9         android:text="最底部" />
10
11     <Button
12         android:layout_width="150px"
13         android:layout_height="150px"
14         android:layout_gravity="center"
15         android:text="中间" />
16
17     <Button
18         android:layout_width="50px"
19         android:layout_height="50px"
20         android:layout_gravity="center"
21         android:text="顶部" />
22 </FrameLayout>

4.TableLayout表格布局
android:shrinkColumns 收缩列
android:stretchColumns 拉伸列
android:collapseColumns 隐藏列
android:layout_column 指定列(作用在列的身上)
android:layout_span 合并列(作用在列的身上)
TableRow单元行里的单元格的宽度小于默认的宽度时就不起作用,其默认是fill_parent,高度可以自定义大小

 1 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2 android:layout_width="match_parent"
 3 android:layout_height="match_parent"
 4 android:shrinkColumns="0"
 5 android:collapseColumns="0" >
 6
 7 <TableRow android:layout_height="wrap_content" >
 8
 9 <Button
10 android:layout_width="wrap_content"
11 android:layout_height="wrap_content"
12 android:text="第一行, 0列" />
13
14 <Button
15 android:layout_width="wrap_content"
16 android:layout_height="wrap_content"
17 android:text="第一行, 1列" />
18
19 <Button
20 android:layout_width="wrap_content"
21 android:layout_height="wrap_content"
22 android:text="第一行, 2列" />
23
24 <Button
25 android:layout_width="wrap_content"
26 android:layout_height="wrap_content"
27 android:text="第一行, 3列" />
28 </TableRow>
29
30 <TableRow android:layout_height="wrap_content" >
31
32 <Button
33 android:layout_width="wrap_content"
34 android:layout_height="wrap_content"
35 android:text="第二行, 0列" />
36
37 <Button
38 android:layout_width="wrap_content"
39 android:layout_height="wrap_content"
40 android:layout_column="2"
41 android:layout_span="2"
42 android:text="第二行, 1列" />
43 </TableRow>
44
45 </TableLayout>

5.AbsoluteLayout绝对布局;(函数中的第四项限)
android:layout_x 指定控件在父布局的x轴坐标
android:layout_y 指定控件在父布局的y轴坐标

android下单元测试:
在AndroidManifest.xml文件中配置一下信息:

在manifest节点下:
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.itheima28.junittest" />

在application节点下配置下面信息:
<uses-library android:name="android.test.runner" />

测试时, 定义一个类继承AndroidTestCase

时间: 2024-07-29 22:49:37

基础学习总结(二)的相关文章

javascript基础学习(二)

javascript的数据类型 学习要点: typeof操作符 五种简单数据类型:Undefined.String.Number.Null.Boolean 引用数据类型:数组和对象 一.typeof操作符 typeof操作符用来检测变量的数据类型,操作符可以操作变量也可以操作字面量. 对变量或值运用typeof操作符得到如下值: undefined----如果变量是Undefined类型: boolean-------如果变量是Boolean类型: number-------如果变量是Numbe

AspectJ基础学习之二搭建环境(转载)

AspectJ基础学习之二搭建环境(转载) 一.下载Aspectj以及AJDT 上一章已经列出了他的官方网站,自己上去download吧.AJDT是一个eclipse插件,开发aspectj必装,他可以提供语法检查,以及编译.这里要说一点重要的知识: aspectj不能使用传统的JDK编译,他的编译器扩展自JDK.AJDT提供的编译功能,就为我们省了很多事,当然你也可以用命令行自己去编译(不过我从来没有这么做过). 无论是apsectj的安装,还是AJDT网上还是有很多文章讲的.不会的同学可以自

javascript 基础学习整理 二 之 html对象总结,参考W3C

Anchor 对象 更改一个链接的文本.URL 以及 target 使用 focus() 和 blur() 向超链接添加快捷键 Document 对象 使用 document.write() 向输出流写文本 使用 document.write() 向输出流写 HTML 返回当前文档的标题 返回当前文档的 URL 返回当前文档的 referrer 返回下载当前文档的服务器域名 使用 getElementById() 使用 getElementsByName() 打开一个新的文档,添加一些文本,然后

JavaScript 基础学习(二)

JavaScript 基础学习(二) instanceof方法: var s = "hello"; var i = 8; //typeof 只能判断基本数据类型 alert(typeof(s)); alert(typeof (i)); //对于引用数据类型,用instanceof var s2=new String("hello2") alert(typeof(s2)); alert(s2 instanceof String);//true var n = new

opengl基础学习专题 (二) 点直线和多边形

题外话 随着学习的增长,越来越觉得自己很水.关于上一篇博文中推荐用一个 学习opengl的 基于VS2015的 simplec框架.存在 一些问题. 1.这个框架基于VS 的Debug 模式下,没有考虑Release版本 2.这个版本中chead,c基础头文件中有些宏设计的不好,例如 //4.0 控制台打印错误信息 #ifndef CERR #define CERR(fmt,...) fprintf(stderr,fmt,##__VA_ARGS__),putchar('\n') #endif/*

Struts2基础学习总结(二)

Struts2基础学习总结(二)---struts.xml参数 1.常量 使用<constant name="" value=""></constant>元素进行描述 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Strut

Java基础学习笔记二十 IO流

转换流 在学习字符流(FileReader.FileWriter)的时候,其中说如果需要指定编码和缓冲区大小时,可以在字节流的基础上,构造一个InputStreamReader或者OutputStreamWriter,这又是什么意思呢? OutputStreamWriter类 查阅OutputStreamWriter的API介绍,OutputStreamWriter 是字符流通向字节流的桥梁:可使用指定的字符编码表,将要写入流中的字符编码成字节.它的作用的就是,将字符串按照指定的编码表转成字节,

Java基础学习笔记二十八 管家婆综合项目

本项目为JAVA基础综合项目,主要包括: 熟练View层.Service层.Dao层之间的方法相互调用操作.熟练dbutils操作数据库表完成增删改查. 项目功能分析 查询账务 多条件组合查询账务 添加账务 编辑账务 删除账务 项目环境搭建 技术选型和jar包介绍 每个项目都要使用一些已经成熟的技术,它们通常是由一些专业组织或团队所提供的开源免费技术.在今后的学习过程中,我们会逐渐对这些专业组织有所了解.本项目中使用的技术如下: apache的commons组件: commons-dbutils

HTML基础学习(二)

3.2 继续上一篇的HTML基础,在几年前制作网页是使用表格标签布局,现在很少使用了,基本是使用div布局 表格:显示表格数据 <table> <tr> <th></th><!--文字居中加粗变大,起到表头作用--> <td></td> </tr> <tr> <td></td> <td></td> </tr> </table>

java基础学习总结二(标识符、字符集、数据类型以及类型转换)

一:标识符 1:标识符可以由字母.数字.下划线_.$符等组成2:标识符的首字母只能是字母.数字.下划线3:标识符不能使用关键字或者保留字4:标识符可以是中文,但是不建议使用中文5:标识符可以任意长,没有限制. 二:字符集 ISO8859-1:标准字符集,西方国家都在使用BIG5:台湾地区使用GB2312:大陆地区最早使用(简体字符集)GBK:在gb2312基础上的扩展,包括简体字和繁体字GB18030:包括简体字.繁体字.藏蒙维吾尔等少数民族语言等 三:数据类型 数据类型分为基本数据类型和引用数