Android开发——Android开发开始
来源:互联网 发布:宁波ug编程培训 编辑:程序博客网 时间:2024/06/06 00:29
常见布局
1.相对布局( RelativeLayout)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="80dp" > <!-- 在指定控件的右边、左边、上边或者下边 --> <TextView android:layout_toRightOf="@id/控件id名" android:layout_toLeftOf="@id/控件id名" android:layout_above="@id/控件id名" android:layout_below="@id/控件id名" /> <!-- 在父窗体中居中、水平居中、或者竖直居中 --> <TextView android:layout_centerInParent="true" android:layout_centerHorizontal="true" android:layout_centerVertical="true" /> <!-- 与父窗体上边、下边、左边或者右边对齐 --> <TextView android:layout_alignParentTop="true" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" /> <!-- 与指定控件的左边、右边、上边或者下边对齐 --> <TextView android:layout_alignLeft="@id/控件id名" android:layout_alignRight="@id/控件id名" android:layout_alignTop="@id/控件id名" android:layout_alignBottom="@id/控件id名" /> <!-- 距离指定控件外边距有xx距离 --> <TextView android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="10dp" android:layout_marginBottom="10dp" /></RelativeLayout>
1.1 px与dp和sp之间的关系
(1)dp:像素密度的比值,是与HVGA相比较的,为了保证不同大小的屏幕中组件出现的位置是相同的
(2)sp:文字的单位,便于文字的缩放,并且不会产生锯齿,与dp大小相同
2.线性布局( LinearLayout)
特点:排列方式自上而下或者自左向右
<?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:orientation="vertical/horizontal" 竖直或者水平排列 --></LinearLayout>
使用:
(1)线性布局与相对布局经常组合使用
(2)Android4.0以后,在系统【Settings】==>【Developer options】==>勾选【show layout bounds】会显示布局的边界线,便于程序员观看布局方式
3.表格布局( TableLayout)
<?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:layout:weight————表示的是权重,权重即为比例、份数。此例子两个表格各站一行的1份和2份。不过要设置width为0dp android:gravity="left/center/right"————是中心所在位置 --> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:gravity="right" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" android:text="卫宫士郎" /> <TextView android:gravity="center" android:layout_weight="2" android:layout_width="0dp" android:layout_height="wrap_content" android:text="远坂凛" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" android:text="卫宫士郎" /> <TextView android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" android:text="远坂凛" /> </TableRow></TableLayout>
4.绝对布局( AbsoluteLayout)
用途:已经被废弃掉的布局方式,不过游戏常使用这种布局方式
特点:会为在此布局中的全部控件添加一个【layout_x="xxdp"】和一个【layout_y="xxdp"】这两个值,指定控件的具体坐标
5.帧布局( FrameLayout)
特点:帧布局的画面是后一个覆盖前一个的结构,可以一层一层的显示出来
<?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" > <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text="我是视频,现在正在播放,点击一下就会暂停" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <Button android:id="@+id/btPlay" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="开始" android:onClick="play" /> <Button android:id="@+id/btPause" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="暂停" android:onClick="pause" /> </LinearLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" > <ImageView android:id="@+id/ivPic" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" android:visibility="invisible" /> </RelativeLayout></FrameLayout>
测试
1.测试相关知识
1.1 根据是否知道源代码分为2种
(1)黑盒测试:测试时不知道源码,只关心程序执行过程和结果。一般这种测试员思维方式与众不同,不按正常流程作业,如发现游戏BUG
(2)白盒测试:根据源码写测试代码与测试用例(测试方法)来完成测试
1.2 根据测试粒度可分为3种
(1)方法测试:function test ===> 测试某些方法
(2)单元测试:unit test ===> 测试几个方法组成的单元
(3)集成测试:integration ===> 测试程序的几个模块
1.3 根据测试的次数分为2种
(1)冒烟测试:smoke test ===> android 猴子,可在Android命令行界面中运行猴子来对手机某些软件进行暴力测试(暴力测试)
(2)压力测试:pressure test ===> 100万个用户登录,100万个http请求
2.Android下的Junit测试框架
出现意义:因为现在的Java的程序不是运行在JVM中,是将运行在Dalvik虚拟机上,所以像main函数和一般的junit测试将无法运行
2.1 建立Junit测试类的步骤
(1)测试类需要继承AndroidTestlase类
(2)写好测试方法运行时,会把应用程序打包装到手机上,给手机发送一些指令,所以需要定义你的指令
(3)在清单文件中添加指令,添加具体如下
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.heima.helloworld.test" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="14" /><!-- 需要添加的第一个节点android:name=""android.test.InstrumentationTestRunner"————指令集名称,固定不变的android:targetPackage="测试所在app应用程序的包名" --> <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.heima.helloworld" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <!-- 需要添加的第二个节点,要用的到函数库,书写格式也是固定不变的 --> <uses-library android:name="android.test.runner" /> </application></manifest>
(4)这是Junit运行测试类即可运行,过程是应用程序打包安装到Android虚拟机中,然后Dalvik解析指令集向工程发送回来信息,测试得以运行
2.2 简单建立清单文件指令集方法
在eclipse中新建工程【AndroidTest Project】,并选择要测试的工程,然后你会发现新建的测试工程的清单文件中已经自动添加好了指令集,你只需复制粘贴即可
Android常见类
1.Context抽象类
位置:android.content.Context包
功能:上下文类,是Activity类的父类体系中最大的父类,获取Activity对象的一些属性信息,类如缓存文件位置、存储文件位置
1.1 Linux文件权限详解
明确:Linux是靠着10字符长的字符串来定义文件权限的
(1)位置0:【-】代表文件 【d】代表目录
(2)位置1-3:表示当前用户对此文件的权限,【r】代表可读,【w】可写,【x】代表可执行,【-】代表不能
(3)位置4-6:表示当前用户所在组中所有成员对此文件的权限,【r】代表可读,【w】代表可写,【x】代表可执行,【-】代表不能
(4)位置7-9:表示其他用户对此文件的权限,【r】代表可读,【w】代表可写,【x】代表可执行,【-】代表不能
注意:权限中的后边9位中的【r、w、x】可以表示二进制的1,【-】表示二进制的0,所以【rw- rw- rw-】可以写成【110 110 110】,即【666】
2.Logcat( 日志猫)
存在意义:因为你的应用程序是运行在虚拟机上的,程序出错异常信息是Davlik虚拟机打印的,你根本看不到。所以这时Logcat会通过adb接口取出虚拟机日志缓冲区中的异常日志信息
日志信息分为5个级别:
(1)Verbose:提醒,黑色
(2)Debug:调试,蓝色
(3)Info:信息,绿色
(4)Warn:警告,橙色
(5)Error:错误,红色
2.1 Log终类
位置:android.util.log
3. Environment类
位置:android.os包,这是一个手机环境对象类
内部存储空间:内存【/data/data】
外部存储空间:SD卡【/mnt/sdcard】或者【/sdcard】
写外部存储设备的权限:android.permission.WRITE_EXTERNAL_SOTRAGE
读外部存储设备的权限:android permission.READ_EXTERNAL_SOTRAGE(4.0以后的新特性,当用户在设置中勾选了【对SD卡进行读写保护】)
4.Formatter类
位置:android.text.format包
5.SharedPreferences接口( 参数类)
位置:android.content包
通过键获取值,并且只能获取String类型的value值,defValue是指当获取的值为空时取的默认值
5.1 SharedPreference.Editor接口
位置:android.content包
6.Xml类
位置:android.util包
7.XmlSerializer接口
位置:org.xmlpull.v1.XmlSerializer包
功能:Xml文件的序列化器
8.XmlPullParser接口
位置:org.xmlpull.v1.XmlPullParser
功能:Xml文件的解析器
8.File类
9.SmsMessage类
- Android开发——Android开发开始
- Android TV开发(—)开始电视应用
- 开始进入Android开发
- 开始学习Android开发
- 开始android游戏开发
- 开始学习android开发
- 开始Android开发
- 开始学习android开发
- Android的开始——开发环境搭建
- 开始学习Android手机开发
- 开始学习android手机开发
- android开发笔记--Helloword开始
- 今天开始学习Android开发
- 开始做android开发了
- 开始做android开发了
- 开始Android开发的学习!
- 开始使用Kotlin开发Android
- Android基础(一)--Android开发开始
- 【hibernate框架】一对多(多对一)双向CRUD-Cascade1
- nodejs 热调试
- Linux软件的卸载-Ubuntu
- 常用知识
- js中setTimeOut传参数
- Android开发——Android开发开始
- Windws MySQL客户端 访问 ubuntu MySQL服务器
- Syntax error, parameterized types are only available if source level is 5.0
- Struts2学习笔记一 ---- 搭建环境
- HTTP协议与HTTPS协议的区别
- 文件描述符总结
- 利用NDK生成.so文件
- spring MVC原理
- Logout: 究竟用GET还是POST?