- 浏览: 14753 次
- 性别:
安卓课程小结
暑假集训完,我们又学了一点关于安卓手机开发的知识,尽管只有几节课,但是收益匪浅啊。
这相当于我们又接触了一门语言啊,俗话说的好师傅领进门,修行在个人啊。
现在就稍微聊聊android开发,
其实我们是以一些小游戏切入来学习android的,有小游戏展开,再讲一些其他的。
首先布局格式
java中的布局靠窗体,面板等来嵌套然后在一个个添加组件,而安卓中则是在xml(res/layout/***.xml)文件中书写组件也在其中按一定顺序写
其格式如下
然后是监听器
监听器也有不同:
java中的监听器addListener(),而后者则是setListener()。
而且,java中的监听器要加在需要监听的地方,而后者则有时不用例如:画图板
不过想一些按钮类的监听器是需要在其上加监听器
注:画图板与java中的不太一样,请看如下代码示例
注:监听器一般写在onCreat()方法所在的类中。
//监听触摸即类似于鼠标监听器
最后是主函数:
java中的main函数可看做Activity中的onCreat方法
Activity中有六个个方法
public class Activity extends ApplicationContext {
protected void onCreate(Bundle savedInstanceState);
protected void onStart();
protected void onRestart();
protected void onResume();
protected void onPause();
protected void onStop();
protected void onDestroy();
}
必备(重写)onCreat()方法。其他根据情况选用(重写)。
重写onCreat方法
重写哦那Destroy()方法
注:android中的界面跳转一定要在*.xml(在项目的根目录下)文件中注册
其实吧,我觉得总体来说我们还是用java语言在写,虽然有些方法不太一样,尤其是在xml文件中
暑假集训完,我们又学了一点关于安卓手机开发的知识,尽管只有几节课,但是收益匪浅啊。
这相当于我们又接触了一门语言啊,俗话说的好师傅领进门,修行在个人啊。
现在就稍微聊聊android开发,
其实我们是以一些小游戏切入来学习android的,有小游戏展开,再讲一些其他的。
首先布局格式
java中的布局靠窗体,面板等来嵌套然后在一个个添加组件,而安卓中则是在xml(res/layout/***.xml)文件中书写组件也在其中按一定顺序写
其格式如下
<?xml version="1.0" encoding="UTF-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="用户登录" android:textSize="30px" tools:context=".MainActivity" /> <!-- 嵌套布局 --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="账号" android:textSize="20px" /> <EditText android:id="@+id/edit_name" android:layout_width="100px" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="密码" android:textSize="20px" /> <EditText android:id="@+id/edit_pwd" android:layout_width="100px" android:layout_height="wrap_content" /> </LinearLayout> <!-- 按钮对象 --> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_gravity="center_horizontal" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登录" android:layout_gravity="center_horizontal" android:id="@+id/btn_login"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="重置" android:layout_gravity="center_horizontal" android:id="@+id/btn_reset"/> </LinearLayout> </LinearLayout>
然后是监听器
监听器也有不同:
java中的监听器addListener(),而后者则是setListener()。
而且,java中的监听器要加在需要监听的地方,而后者则有时不用例如:画图板
不过想一些按钮类的监听器是需要在其上加监听器
注:画图板与java中的不太一样,请看如下代码示例
public class MyView extends ImageView { //位图对象 Bitmap map; //画布对象 Canvas c; //画笔对象 Paint paint; float x1, y1, x2, y2; public MyView(Context context, AttributeSet attrs) { super(context, attrs); /** * 实例化对象 */ map = Bitmap.createBitmap(300, 400, Config.ARGB_8888); c = new Canvas(map); paint = new Paint(); } public boolean onTouchEvent(MotionEvent me) { // 获取坐标 int action = me.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: x1 = me.getX(); y1 = me.getY(); break; case MotionEvent.ACTION_UP: x2 = me.getX(); y2 = me.getY(); invalidate(); break; } return true; } protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawLine(x1,y1, x2), y2, paint); canvas.drawBitmap(map, 0, 0, null); } }
注:监听器一般写在onCreat()方法所在的类中。
public class main extends Activity { public static String tool = "Line"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getTool(); } /** * 监听器 */ OnClickListener listener = new OnClickListener(){ @Override public void onClick(View v) { int id = v.getId(); switch(id){ case R.id.black: color=Color.BLACK; break; case R.id.green: color=Color.GREEN; break; case R.id.white: color=Color.WHITE; break; } } } ; /** *给工具按钮添加监听器 */ public void getTool() { Button Oval = (Button) findViewById(R.id.Oval); Button Line = (Button) findViewById(R.id.Line); Button Rect = (Button) findViewById(R.id.Rect); Oval.setOnClickListener(listener1); Line.setOnClickListener(listener1); Rect.setOnClickListener(listener1); } }
//监听触摸即类似于鼠标监听器
public boolean onTouchEvent(MotionEvent me) { // 获取坐标 int action = me.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: x1 = me.getX(); y1 = me.getY(); break; case MotionEvent.ACTION_UP: x2 = me.getX(); y2 = me.getY(); if (main.tool.equals("Line")) { shape = new ShapeLine(x1, x2, y1, y2, paint, 5, main.color); mq.add(shape); } if(main.tool.equals("Rect")){ shape = new ShapeRect(x1,x2,y1,y2,paint,1,main.color); mq.add(shape); } if(main.tool.equals("Oval")){ shape = new ShapeOval(x1,x2,y1,y2,paint,1,main.color); mq.add(shape); } invalidate(); break; } return true; }
最后是主函数:
java中的main函数可看做Activity中的onCreat方法
Activity中有六个个方法
public class Activity extends ApplicationContext {
protected void onCreate(Bundle savedInstanceState);
protected void onStart();
protected void onRestart();
protected void onResume();
protected void onPause();
protected void onStop();
protected void onDestroy();
}
必备(重写)onCreat()方法。其他根据情况选用(重写)。
重写onCreat方法
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //获取按钮对象 bu_add = (Button)findViewById(R.id.addBall); bu_pause = (Button)findViewById(R.id.pause); bu_remove=(Button)findViewById(R.id.remove); bu_add.setOnClickListener(click); bu_pause.setOnClickListener(click); bu_remove.setOnClickListener(click); }
重写哦那Destroy()方法
protected void onDestroy() { super.onDestroy(); list.clear(); };
注:android中的界面跳转一定要在*.xml(在项目的根目录下)文件中注册
其实吧,我觉得总体来说我们还是用java语言在写,虽然有些方法不太一样,尤其是在xml文件中
发表评论
-
初识百度地图
2012-08-21 14:25 1461初学android,初看百度地图,感到迷茫,不知我的地图在何方 ... -
树小结
2012-08-02 09:28 8221.树的概述 树代表一种非线性的,复杂的二维结构。 2.树的 ... -
线程小结
2012-08-02 09:15 7091.线程 每一个java程序中至少都有一个线程——主线程。当j ... -
链表总结
2012-08-02 09:04 8541.链表总结 链表是是一种物理存储单元上非连续,非顺序的存储结 ... -
IO流
2012-07-17 10:35 819IO流 java中的输入输出抽 ... -
文件
2012-07-16 22:05 743二.文件 文件类型: 真实文件,虚拟内存文件,目录文件 文件格 ... -
集合总结
2012-07-16 19:48 864一.集合 1.java中的集合类型 1)Set Set特点 ... -
java中的异常机制
2012-07-11 14:17 8191.什么是异常 简单来说,异常是指可能导致程序出错的原因,使程 ... -
基础知识
2012-07-05 08:24 707... -
数组队列总结
2012-05-28 12:08 808一:数组 1. 数组是一个容器 1.数组在定义时大小已固定 ... -
关键字总结
2012-05-19 09:27 826关键字总结 1.访问修饰符 public 共 ...
相关推荐
最新android手机开发,2011年11月24日整理而成
android手机开发基本知识介绍 android手机开发基本知识介绍 android手机开发基本知识介绍
android手机游戏开发大全
【最全最详细】android开发实习报告总结 范文.pdf【最全最详细】android开发实习报告总结 范文.pdf【最全最详细】android开发实习报告总结 范文.pdf【最全最详细】android开发实习报告总结 范文.pdf【最全最详细】...
教程名称:3G手机Android应用开发系列视频教程课程目录:【】3G手机Android应用开发第七天课程4.编码实现软件界面【】3G手机Android应用开发第二天课程1.单元测试与输出日志信息【】3G手机Android应用开发第二天课程...
1.3 小结 第2章 Android开发环境搭建 2.1 Android开发准备工作 2.2 开发包及其工具的安装和 配置 2.2.1 安装JDK和配置Java开发 环境 2.2.2 Eclipse的安装与汉化 2.2.3 SDK和ADT的安装和 配置 2.3 创建第一个Android...
用android开发的手机通讯录,能够实现手机添加通讯信息,登陆启用密码和解除密码保护!
第2篇为应用开发篇,通过实例介绍了Android UI布局、Android人机界面、手机硬件设备的使用、Android本地存储系统、Android中的数据库、多线程设计、Android传感器、Android游戏开发基础、Android与Internet,以及...
淮海工学院计算机工程学院 开放实验... " ----------------------- 《Android应用开发》开放实验项目总结报告-模板全文共2页,当前为第1页。 《Android应用开发》开放实验项目总结报告-模板全文共2页,当前为第2页。
3G手机开发之Android应用开发 3G手机开发视频教程
android手机开发的必备素材,相当的全,欢迎下载使用
课程表--android 手机开发 java 课程表--android 手机开发 java 课程表--android 手机开发 java 课程表--android 手机开发 java 课程表--android 手机开发 java 课程表--android 手机开发 java
Android课程开始了,想学的话,可以看看,之后陆续会有补充的;今天是第一课--Android开发环境搭建;童鞋们,千万不要错过啊!!
手机开发 移动开发 android \android学习资料大全
开发过一款手机管家项目,该项目实现了目前市面上手机管家的核心功能,主要包括以下内容 (1).内存管理功能 (2).手机清理 (3).应用管理(手机应用的删除、分享与启动)功能 (4).骚扰拦截功能 (5)病毒...
android开发笔记总结
Android手机开发平台的搭建:ADT、sdk的部署开发
Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。...
手机软件开发项目,实例,可以参考则玩哦,你会发现开发手机软件同样很方便和简单,Android手机软件可以自己开发啦!
《创意之钥:Android手机交互应用开发》以android手机交互开发为平台,定位于创意从产生到实际应用的过程,将书中内容分为创意的真空、创意的奇点和创意大爆炸三篇。作者分别从灵感的获取、如何在android开发中发挥...