课程:程序设计与数据结构html
班级:1623java
姓名:张韵琪android
学号:20162307git
指导教师:娄佳鹏老师、王志强老师网络
实验日期:2017年5月26号数据结构
实验密级:非密级app
实验时间:一周编辑器
必修/选修:必修ide
实验名称:Android程序设计工具
实验仪器:电脑
实验目的与要求:
目的:
学习Android程序设计
要求:
1.没有Linux基础的同窗建议先学习《Linux基础入门(新版)》《Vim编辑器》 课程 2.完成实验、撰写实验报告,实验报告以博客方式发表在博客园,注意实验报告重点是运行结果,遇到的问题(工具查找,安装,使用,程序的编辑,调试,运行等)、解决办法(空洞的方法 如“查网络”、“问同窗”、“看书”等一概得0分)以及分析(从中能够获得什么启示,有什么收获,教训等)。报告能够参考范飞龙老师的指导 3. 严禁抄袭,有该行为者实验成绩归零,并附加其余惩罚措施。
安装 Android Studio (Mac版)
- 到官网安装Android Studio 官网地址:https://developer.android.google.cn/studio/index.html
- 选择 我已阅读并赞成上述条款及条件
- 下载完毕以后,将 Android Studio 拖放到“Applications”文件夹中,而后启动 Android Studio。
- 选择是否想要导入以前的 Android Studio 设置,而后点击 OK。
- 以后 Android Studio 设置向导将指导您完成余下的设置,包括下载开发所需的 Android SDK 组件
关于git push问题
- 先参考此篇博客
- 再打开终端,具体命令:
localhost:~ zhangyunqi$ history 注意:前面序号不要管 32 cd AndroidStudioProjects/ 33 ls 34 cd zhangyunqiapp2(你的AndroidStudio 本身起的名字) 35 ls 36 ls -a 37 git push 38 ls 39 cd zhangyunqiapp2 40 ls 41 git status 42 git add . 43 git commit -m "gradle" 44 git push 45 git push --set-upstream origin master 46 git pull 47 git branch 48 git status 49 git pull 50 git branch 51 git branch /? 52 ls 53 git status 54 cd .. 55 ls 56 ls 57 mkdir Tiffany4 58 cd Tiffany4 59 ls 60 git clone http://git.oschina.net/pdds2017/20162307androidapp.git(码云上的连接) 61 ls 62 cd 20162307androidapp 63 ls 64 cd .. 65 ls 66 cd .. 67 ls 68 cd zhangyunqiapp2 69 ls 70 git clone http://git.oschina.net/pdds2017/20162307androidapp.git 71 ls 72 ls -a 73 rm.git 74 rm -rf .git 75 ls 76 ls -a 77 rm .gitignore 78 ls -a 79 mv *.* 20162307androidapp/ 80 ls 81 mv build/ 20162307androidapp/ 82 mv gradle 20162307androidapp/ 83 mv gradlew 20162307androidapp/ 84 mv app/ 20162307androidapp/ 85 ls 86 ls -a 87 mv .gradle/ 20162307androidapp/ 88 mv .idea/ 20162307androidapp/ 89 ls 90 cd 20162307androidapp/ 91 ls 92 git add . 93 ls 94 git commit -m "finish android projects" 95 git push
Android Studio的安装测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十四章: - 安装 Android Studio - 完成Hello World, 要求修改res目录中的内容,Hello World后要显示本身的学号,提交代码运行截图和码云Git连接,截图没有学号要扣分 - 学习Android Studio调试应用程序
1.按照娄老师所给的博客,建立a new Android Studio project . 博客连接:http://www.cnblogs.com/rocedu/p/6824965.html
2.而后 res目录-->layout目录-->activity_main.xml将android:text="Hello World!" 改成android:text="Hello World!20162307"
Activity测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十五章: - 构建项目,运行教材相关代码 - 建立 ThirdActivity, 在ThirdActivity中显示本身的学号,修改代码让MainActivity启动ThirdActivity - 提交代码运行截图和码云Git连接,截图要有学号水印,不然会扣分
1.app右键--> new-->Activity-->Gallery,选择Empty Activity而后点击next
2.接下来的界面
3.点击finish
4.在MainActivity原有的代码的基础上加上下面的代码
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onTouch(View v, MotionEvent event) { Intent intent = new Intent(this, ThirdActivity.class); intent.putExtra("message", "20162307张韵琪实验2"); startActivity(intent); return true; }
5.将ThirdActivity改成
public class ThirdActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_third); Intent intent = getIntent(); String message = intent.getStringExtra("message"); ((TextView) findViewById(R.id.textView1)).setText(message); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); return true; } }
6.在activity_third.xml中添加一段代码:
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView1" />
7.在AndroidManifest.xml添加下面的代码
<intent-filter> <action android:name="com.blackay.test.helloworld.ThirdActivity" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
UI测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十六章: - 构建项目,运行教材相关代码 - 修改代码让Toast消息中显示本身的学号信息 - 提交代码运行截图和码云Git连接,截图要有学号水印,不然会扣分
MainActivity.java代码:
package com.example.zhangyunqi.zhangyunqiapp; import android.content.Context; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.app.Activity; import android.util.AttributeSet; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btnshow1 = (Button) findViewById(R.id.btn1); btnshow1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast toast = Toast.makeText(MainActivity.this, "20162307张韵琪实验3", Toast.LENGTH_LONG); toast.show(); } }); } }
activity_main.xml代码:
<?xml version="1.0" encoding="utf-8"?> <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" android:paddingBottom="10dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp" tools:context=".MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="first_screen" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="20162307张韵琪实验3" android:id="@+id/btn1" android:layout_alignParentTop="true" android:layout_marginTop="31dp" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> </RelativeLayout>
布局测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十七章: - 构建项目,运行教材相关代码 - 修改布局让P290页的界面与教材不一样 - 提交代码运行截图和码云Git连接,截图要有学号水印,不然会扣分
activity_main.xml代码:
<?xml version="1.0" encoding="utf-8"?> <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" android:paddingBottom="10dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp" tools:context=".MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="first_screen" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="20162307张韵琪实验4" android:id="@+id/btn1" android:layout_alignParentTop="true" android:layout_marginTop="31dp" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <FrameLayout android:layout_width="368dp" android:layout_height="495dp" android:orientation="horizontal" tools:layout_editor_absoluteX="11dp" tools:layout_editor_absoluteY="16dp"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="160dp" android:layout_marginTop="150dp" android:text="20162307实验4" /> <ImageButton android:id="@+id/imageButton" android:layout_width="131dp" android:layout_height="69dp" android:layout_marginLeft="160dp" android:layout_marginTop="140dp" android:alpha="0.4" android:src="@android:drawable/btn_star_big_on" /> </FrameLayout> </RelativeLayout>
事件处理测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十八章: - 构建项目,运行教材相关代码 - 提交代码运行截图和码云Git连接,截图要有学号水印,不然会扣分
activity_main.xml代码:
<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" android:paddingBottom="40dp" android:paddingLeft="40dp" android:paddingRight="40dp" tools:context=".MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="20162307实验5"></TextView> <AnalogClock android:id="@+id/analogClock1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="200dp" android:onClick="changeColor" /> </RelativeLayout>
MainActivity.java代码:
package com.example.zhangyunqi.zhangyunqiapp; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.AnalogClock; public class MainActivity extends Activity { int counter = 0; int[] colors = {Color.BLACK, Color.BLUE, Color.CYAN, Color.DKGRAY, Color.GRAY, Color.GREEN, Color.LTGRAY, Color.MAGENTA, Color.RED, Color.WHITE, Color.YELLOW}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void changeColor(View view) { if (counter == colors.length) { counter = 0; } view.setBackgroundColor(colors[counter++]); } }
步骤 | 耗时 | 百分比 |
---|---|---|
需求分析 | 60min | 14.0% |
代码实现 | 170min | 39.5% |
测试 | 150min | 34.9% |
分析总结 | 50min | 11.6% |
以为AndroidStudio是一个新的体验,和以前学习的不大相同,在AndroidStudio中git是最麻烦的,是最难弄的,因此我把怎么弄git写在个人博客里。