Android基础——01快速入门
2015-10-05 16:17
791 查看
1G到4G的介绍
1G 大哥大(只能打电话)2G 小灵通(可以发短信)
3G 沃 可以上网,浏览图片,使用协议是wap.baidu.com 速度可以达到7.2M
4G lte 100M/s
5G 华为在研究的, 投资6亿美金 传说中的速度可以达到10G/s
Android操作系统的介绍
安卓系统最初由安迪 鲁宾等人开发制作最初开发这个项目的目的是创建一个数码相机的先进操作系统
后来被改造为一款面向智能手机的操作系统
于2005年被美国科技企业Google收购
Android系统版本介绍
Android系统构成
【1】linux层
【2】函数库层,由c或者c++写的
【3】Application frameWork应用的框架层
【4】最上层,应用层
jvm与dvm的介绍
jvm是sun公司的产品,dvm是Google公司的产品,刚开始Google使用的jvm被sun公司给告了,后来Google就自己研发了dvm两者的区别是:
【1】dvm吧所有的.class文件变成一个dex文件
【2】基于的架构不同
【3】为什么谷歌自己研发dvm,是由于版权的原因
补充:art模式和传统模式的概念和区别:
开发环境的搭建
eclipse IBM研发的软件,开发语言是java【1】解压安装环境
【2】安装jdk才能用
sdkManager介绍
dx.bat 把所有的.class文件变成了一个dex文件aapt Android应用打包工具
adb Android调试桥
获取SDK 工具包
在eclipse开发工具中,打开sdkManager是这样的
模拟器的简介及创建
Android版本对应的API级别
2.3——-10
3.0——-11
4.0——-14
4.1.2—–16
Android常见的分辨率
320*480
480*800
1280*720
DDMS透视图介绍
helloworld案例
案例实现的代码:Android的工程目录结构
src java原代码存放目录gen 自动生成目录
gen 目录中存放所有由Android开发工具自动生成的文件。目录中最重要的就是R.java文件。 这个文件由Android开发工具自动产生的。Android开发工具会自动根据你放入res目录的资源,同步更新修改R.java文件。正因为R.java文件是由开发工具自动生成的,所以我们应避免手工修改R.java。R.java在应用中起到了字典的作用,它包含了各种资源的id,通过R.java,应用可以很方便地找到对应资源。另外编绎器也会检查R.java列表中的资源是否被使用到,没有被使用到的资源不会编绎进软件中,这样可以减少应用在手机占用的空间。
res/ 资源(Resource)目录
在这个目录中我们可以存放应用使用到的各种资源,如xml界面文件,图片或数据。具体请看ppt下方备注栏。
libs/ 支持库目录
程序开发时需要的一些三方的jar包可以放在这个目录,系统会自动把里面的jar包,添加到环境变量。
assets资源目录
Android除了提供/res目录存放资源文件外,在/assets目录也可以存放资源文件,而且/assets目录下的资源文件不会在R.java自动生成ID,所以读取/assets目录下的文件必须指定文件的路径,如:file:///android_asset/xxx.3gp
AndroidManifest.xml 项目清单文件
这个文件列出了应用程序所提供的功能,以后你开发好的各种组件需要在该文件中进行配置,如果应用使用到了系统内置的应用(如电话服务、互联网服务、短信服务、GPS服务等等),你还需在该文件中声明使用权限。
project.properties 项目环境信息,一般是不需要修改此文件
android中res目录中文件详解
一、res/drawable 专门存放png、jpg等图标文件。在代码中使用getResources().getDrawable(resourceId)获取该目录下的资源。
二、res/layout 专门存放xml界面文件,xml界面文件和HTML文件一样,主要用于显示用户操作界面。
三、res/values 专门存放应用使用到的各种类型数据。不同类型的数据存放在不同的文件中,如下:
1)strings.xml 定义字符串和数值,在Activity中使用getResources().getString(resourceId) 或getResources().getText(resourceId)取得资源。
它的作用和struts中的国际化资源文件一样。
3)colors.xml 定义颜色和颜色字串数值,你可以在Activity中使用getResources().getDrawable(resourceId) 以及getResources().getColor(resourceId)取得这些资源。例子如下:
<?xml version="1.0" encoding="UTF-8"?> <resources> <color name="contents_text">#ff0000</color> </resources>
4)dimens.xml 定义尺寸数据,在Activity中使用getResources().getDimension(resourceId) 取得这些资源
<?xml version="1.0" encoding="UTF-8"?> <resources> <dimen name="key_height">50dip</dimen> </resources>
5)styles.xml 定义样式。
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="itcastText" parent="@style/Text"> <item name="android:textSize">18sp</item> <item name="android:textColor">#0066FF</item> </style> </resources>
四、res/anim/ 存放定义动画的XML文件。
五、res/xml/ 在Activity中使用getResources().getXML()读取该目录下的XML资源文件。
六、res/raw/ 该目录用于存放应用使用到的原始文件,如音效文件等。编译软件时,这些数据不会被编译,它们被直接加入到程序安装包里。
为了在程序中使用这些资源,你可以调用getResources().openRawResource(ID) , 参数ID形式:R.raw.somefilename。
Android的打包过程
adb指令练习
电话拨号器的案例
【1】 画UI【2】 写对应的业务逻辑
package com.itheima.phonedail; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends Activity { private EditText et_number; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //加载一个布局 setContentView(R.layout.activity_main); //[1]找到我们关心的控件 edittext button et_number = (EditText) findViewById(R.id.editText1); //[2]找到按钮 Button btn_call = (Button) findViewById(R.id.button1); //[3]给button按钮设置一个点击事件 btn_call.setOnClickListener(new MyClickListener()); } //定义一个类去实现 按钮需要的接口类型 private class MyClickListener implements OnClickListener{ //Called when a view has been clicked. 当按钮被点击的时候调用 @Override public void onClick(View v) { //[4]获取edittext 文本内容 String number = et_number.getText().toString().trim(); if ("".equals(number)) { /** * context 上下文 */ Toast.makeText(MainActivity.this, "number不能为空", 1).show(); return; } //[5]进行拨打电话 意图 Intent Intent intent = new Intent(); //创建一个意图对象 打 猫 狗 代码 电话 //[5.1]设置动作 intent.setAction(Intent.ACTION_CALL); //[5.2]设置要拨打的数据 /** * uri:统一资源标示符 自己定义的路径 想代表什么就代表说明 * url:统一资源定位符 www.baidu.com */ intent.setData(Uri.parse("tel:"+number)); //[6]开启意图 startActivity(intent); } } }
涉及到打电话,调用手机自身的功能的时候一定要在清单文件中给设置权限
【3】 测试
按钮的四种点击方式
【1】内部类的方式(上边例子中用到的方法)【2】匿名内部类的方式
package com.itheima.phonedail; import com.itheima.click2.R; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends Activity { private EditText et_number; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //加载一个布局 setContentView(R.layout.activity_main); //[1]找到我们关心的控件 edittext button et_number = (EditText) findViewById(R.id.editText1); //[2]找到按钮 Button btn_call = (Button) findViewById(R.id.button1); //[3]给button按钮设置一个点击事件 //☆☆☆☆ 按钮第二种点击事件 匿名内部类的方式 btn_call.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //[4]实现拨打电话的逻辑 callPhone(); } }); } private void callPhone() { //[4]获取edittext 文本内容 String number = et_number.getText().toString().trim(); if ("".equals(number)) { /** * context 上下文 */ Toast.makeText(MainActivity.this, "number不能为空", 1).show(); return; } //[5]进行拨打电话 意图 Intent Intent intent = new Intent(); //创建一个意图对象 打 猫 狗 代码 电话 //[5.1]设置动作 intent.setAction(Intent.ACTION_CALL); //[5.2]设置要拨打的数据 /** * uri:统一资源标示符 自己定义的路径 想代表什么就代表说明 * url:统一资源定位符 www.baidu.com */ intent.setData(Uri.parse("tel:"+number)); //[6]开启意图 startActivity(intent); } }
【3】让当前类实现OnClickListener接口类型(适用于界面上有多种按钮的情况)
package com.itheima.phonedail; import com.itheima.click3.R; import android.net.Uri; import android.os.Bundle; import android.R.layout; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends Activity implements OnClickListener { private EditText et_number; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 加载一个布局 setContentView(R.layout.activity_main); // [1]找到我们关心的控件 edittext button Button btn_call2 = (Button) findViewById(R.id.button2); Button btn_call3 = (Button) findViewById(R.id.button3); Button btn_call4 = (Button) findViewById(R.id.button4); et_number = (EditText) findViewById(R.id.editText1); // [2]找到按钮 Button btn_call = (Button) findViewById(R.id.button1); // [3]给button按钮设置一个点击事件 // ☆☆☆☆ 按钮第三种点击事件 btn_call.setOnClickListener(this); btn_call2.setOnClickListener(this); btn_call3.setOnClickListener(this); btn_call4.setOnClickListener(this); } private void callPhone() { // [4]获取edittext 文本内容 String number = et_number.getText().toString().trim(); if ("".equals(number)) { /** * context 上下文 */ Toast.makeText(MainActivity.this, "number不能为空", 1).show(); return; } // [5]进行拨打电话 意图 Intent Intent intent = new Intent(); // 创建一个意图对象 打 猫 狗 代码 电话 // [5.1]设置动作 intent.setAction(Intent.ACTION_CALL); // [5.2]设置要拨打的数据 /** * uri:统一资源标示符 自己定义的路径 想代表什么就代表说明 url:统一资源定位符 www.baidu.com */ intent.setData(Uri.parse("tel:" + number)); // [6]开启意图 startActivity(intent); } // 当我点击按钮的时候执行 @Override public void onClick(View v) { // 具体判断点击的是哪个按钮 switch (v.getId()) { case R.id.button1: // 代表点击了第一按钮 callPhone(); break; case R.id.button2: // 代表点击了第一按钮 callPhone(); break; case R.id.button3: // 代表点击了第一按钮 callPhone(); break; case R.id.button4: // 代表点击了第一按钮 System.out.println("我被削了"); break; default: break; } } }
【4】通过在UI的xml文件中设置onclick属性设置值,这个值就是要在Activity里面要实现的方法名
package com.itheima.phonedail; import com.itheima.click4.R; import android.net.Uri; import android.os.Bundle; import android.R.layout; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends Activity implements OnClickListener { private EditText et_number; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 加载一个布局 setContentView(R.layout.activity_main); } //☆☆☆☆☆ 按钮的第四种点击事件 声明一个方法 方法名和你要点击的这个按钮 在布局中生命的onClieck属于一样 public void click(View v){ //拨打电话 callPhone(); } private void callPhone() { // [4]获取edittext 文本内容 String number = et_number.getText().toString().trim(); if ("".equals(number)) { /** * context 上下文 */ Toast.makeText(MainActivity.this, "number不能为空", 1).show(); return; } // [5]进行拨打电话 意图 Intent Intent intent = new Intent(); // 创建一个意图对象 打 猫 狗 代码 电话 // [5.1]设置动作 intent.setAction(Intent.ACTION_CALL); // [5.2]设置要拨打的数据 /** * uri:统一资源标示符 自己定义的路径 想代表什么就代表说明 url:统一资源定位符 www.baidu.com */ intent.setData(Uri.parse("tel:" + number)); // [6]开启意图 startActivity(intent); } }
Android中常用的布局
【1】线性布局布局方式有水平布局和垂直布局,
就像羊肉串一样的,以垂直布局为例,定义的组件会一个一个的往下边排列
<?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" > <TextView android:id="@+id/tv_number" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:text="请输入电话号码" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入电话号码" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="拨打" /> </LinearLayout>
【2】相对布局
不管定义多少组件,默认都是按照在左上方重叠排放,这就用到了每个组件的相对距离
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <TextView android:id="@+id/tv_number" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="请输入number" /> <EditText android:id="@+id/et_number" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/tv_number" android:hint="请输入电话号码" /> <Button android:id="@+id/btn_call" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/et_number" android:text="call" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/et_number" android:layout_toRightOf="@id/btn_call" android:text="call" /> </RelativeLayout>
【3】帧布局
就像播放器里面暂停的时候一样,在一个组件里面可以嵌套另一个组件
<?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:text="哈哈哈哈" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="play" /> </FrameLayout>
【4】表格布局
一个行标签代表一样,里面设置了几个组件,就表示有几列
<?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" > <!-- 代表一行 --> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="哈哈" android:textSize="18sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="呵呵" android:textColor="#FF007D" android:layout_marginLeft="30dp" android:textSize="18sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="嘿嘿" android:textColor="#000000" android:layout_marginLeft="30dp" android:textSize="18sp" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="哈哈" android:textSize="18sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="呵呵" android:textColor="#FF007D" android:layout_marginLeft="30dp" android:textSize="18sp" /> </TableRow> </TableLayout>
【5】绝度布局
该布局已经被谷歌工程师废弃掉了,因为不适用于屏幕的适配,但是有些地方还用的上,就像手机斗地主里面的三个人的位置,是固定的一样,里面是根据X轴Y轴的坐标来控制组件的位置
<?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:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="79dp" android:layout_y="64dp" android:text="Button" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="186dp" android:layout_y="33dp" android:text="Button" /> </AbsoluteLayout>
Android中的单位
sp和dp:sp只用在textView中用来设置文字的大小的单位
dp是用来控制其他组件的大小的,在安卓中表示大小的单位使用dp不用px
相关文章推荐
- Android基础学习之异步任务使用Thread(线程)
- Android:Material Design(一) 概述
- Android Notification
- Android性能专项测试之MAT
- 【教程】用安卓厨房制作你自己的卡刷包!你也可以是Romer !
- android SharedPreferences数据的短时间存储
- Android 学习笔记9——socket通信
- Binder进程间通信机制的Service Manager代理对象获取过程
- android 模拟器命令 附:模拟器不能联网设置
- Android-小知识点-去掉顶端标题栏
- Android基础学习之消息发送使用Looper
- Android 自定义RadioButton 实现文字上下左右方向的图片大小设置
- Android开发最佳实践
- android----(分组、图片滑动)
- Android里merge和include标签的使用
- Android应用调度初始化流程优化方案
- 谷歌宣布Android auto目前的汽车系统汽车市场的影响
- 帮朋友急招PHP、Android开发工程师 西安 工资8k-12k
- Android源码之Gallery专题研究(2)
- Android从无知到有知——NO.7