




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、實(shí)驗(yàn)一 Android開發(fā)環(huán)境搭建與Hello world一、實(shí)驗(yàn)?zāi)康?學(xué)會(huì)搭建并安裝Android開發(fā)環(huán)境,并實(shí)現(xiàn)Hello World應(yīng)用開發(fā)。2、 主要儀器設(shè)備及套數(shù) 計(jì)算機(jī)三、實(shí)驗(yàn)內(nèi)容 搭建開發(fā)環(huán)境;安裝Java JDK,下載Eclipse, 解壓Eclipse;官方下安裝 ADT (Android Development Tools);安裝Android;安裝手機(jī)USB驅(qū)動(dòng);建立新項(xiàng)目,實(shí)現(xiàn)Hello World4、 程序代碼package com.example.helloandroid;import android.support.v7.app.ActionBarActivity
2、;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;public class MainActivity extends ActionBarActivity Overrideprotected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Overridepublic boolean onCreateOpti
3、onsMenu(Menu menu) / Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;Overridepublic boolean onOptionsItemSelected(MenuItem item) / Handle action bar item clicks here. The action bar will/ automatically handle clicks on the
4、 Home/Up button, so long/ as you specify a parent activity in AndroidM id = item.getItemId();if (id = R.id.action_settings) return true;return super.onOptionsItemSelected(item);5、 實(shí)驗(yàn)結(jié)果六、實(shí)驗(yàn)小結(jié)這個(gè)實(shí)驗(yàn)很簡(jiǎn)單,主要是要我們學(xué)習(xí)Android開發(fā)環(huán)境的搭建,了解Android應(yīng)用開發(fā)程序的開發(fā)過程,生成Android應(yīng)用程序框架以及配置相應(yīng)的運(yùn)行參數(shù)。實(shí)驗(yàn)二 界面設(shè)計(jì):空間與布局1、
5、 實(shí)驗(yàn)?zāi)康?Android編程基礎(chǔ),UI設(shè)計(jì);使學(xué)生了解Android編程原理; 掌握界面控件設(shè)計(jì);掌握控件的事件處理編程。2、 主要儀器設(shè)備及套數(shù)計(jì)算機(jī)3、 實(shí)驗(yàn)內(nèi)容 了解各種空間的基本功能: Menu, TextView EditText ,Button, Radio button, List; 了解布局layout 的應(yīng)用;利用布局安排各種控件,設(shè)計(jì)良好用戶界面 。四、程序代碼Package com.example.Edittext;Import android.os.Bundle;Import android.app.Activity;Import android.view.Menu;
6、Import android.widget.RadioGroup;Import android.widget.RadioGroup.OnCheckedChangeListener;Import android.widget.TextView;public class MainActivity extends Activity RadioGroup button01;TextView show;Overrideprotected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setConte
7、ntView(R.layout.activity_main);/獲取界面上button01,show兩個(gè)組件對(duì)象Button01=(RadioGroup)findviewByid(R.Id.button01);Show=(TextView)findviewByid(R.Id.button01);/為RadioGro組件的oncheck事件綁定時(shí)間監(jiān)聽器Button01.setoncheckedchangelistener(new OnCheckedChangeListener() Overridepublic void onCreateOptionMenu(RadioGroup group,i
8、nt checkedId) /根據(jù)勾選的單選按鈕來動(dòng)態(tài)改變tip字符串的值String tip=checkedId=R.id.boy?“男人”:“女人”;/修改show組件中的文本Show.setText(tip););Overridepublic boolean onCreateOptionMenu(Menu menu) getMenuInflater().inflate(R.menu.main,menu);return true;五、實(shí)驗(yàn)結(jié)果運(yùn)行:效果:六、實(shí)驗(yàn)小結(jié) 通過這次試驗(yàn),我對(duì)安卓編程有了進(jìn)一步的認(rèn)識(shí),對(duì)各控件的熟練應(yīng)用會(huì)幫我們大大減少少編程量,另外界面的布局還會(huì)影響到設(shè)計(jì)界面的美
9、觀。實(shí)驗(yàn)三 Android觸控監(jiān)聽器的使用一、實(shí)驗(yàn)?zāi)康?.掌握Android項(xiàng)目中界面顯示的基本方法;2.掌握OnTouchListener監(jiān)聽器的設(shè)計(jì)與使用3.掌握Android手機(jī)硬件API的調(diào)用方法。二、主要儀器設(shè)備及套數(shù)計(jì)算機(jī)三、實(shí)驗(yàn)內(nèi)容在Android平臺(tái)下設(shè)計(jì)實(shí)現(xiàn)滑動(dòng)的方塊應(yīng)用 1. 使用屏幕觸控,圖拽方塊移動(dòng)。2.暫不考慮橫屏切換4、 程序代碼控制文件:package com.ex06_03;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.vie
10、w.MotionEvent;import android.view.View;import android.view.View.OnTouchListener;public class MainActivity extends Activity int x1=150,y1=50; TestView testView; Override public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); testView = new TestView(this); testView.setOnTo
11、uchListener(new mOnTouch(); testView.getXY(x1, y1); setContentView(testView); private class mOnTouch implements OnTouchListener public boolean onTouch(View v, MotionEvent event)if (event.getAction() = MotionEvent.ACTION_MOVE) /在屏幕上滑動(dòng)(拖動(dòng))x1 = (int) event.getX();y1 = (int) event.getY(); testView.getXY
12、(x1, y1); setContentView(testView);if (event.getAction() = MotionEvent.ACTION_DOWN) /點(diǎn)擊x1 = (int) event.getX();y1 = (int) event.getY();Log.i("x=", String.valueOf(x1); Log.i("y=", String.valueOf(y1); testView.getXY(x1, y1); setContentView(testView);return true;package com.ex06_03;
13、import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.view.View;public class TestView extends View int x, y;public TestView(Context context) super(context);void getXY(int _x, int _y)x = _x;y = _y;/* 下面編寫繪制小球的代碼,參見教材例6
14、3 */ protected void onDraw(Canvas canvas) super.onDraw(canvas); /*設(shè)置背景為青色*/ canvas.drawColor(Color.CYAN); Paint paint=new Paint(); /*去鋸齒*/ paint.setAntiAlias(true); /*設(shè)置paint的顏色*/ paint.setColor(Color.BLACK); /*畫一個(gè)實(shí)心圓*/ canvas.drawRect(x, y, x+30, y+30,paint); paint.setColor(Color.GREEN); /*canvas.d
15、rawRect(x-6, y-6, 3,3, paint);*/ 界面布局:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:la
16、yout_width="fill_parent" android:layout_height="wrap_content" android:text="string/hello" /></LinearLayout>5、 實(shí)驗(yàn)結(jié)果6、 實(shí)驗(yàn)小結(jié) 簡(jiǎn)單觸摸屏事件指在觸摸屏上按下、抬起、滑動(dòng)的事件,在Android系統(tǒng)中,通過OnTouchListener監(jiān)聽接口來處理屏幕事件當(dāng)在View的范圍內(nèi)進(jìn)行按下、抬起、滑動(dòng)等動(dòng)作時(shí)都會(huì)觸發(fā)該事件。在本次試驗(yàn)中我學(xué)會(huì)了簡(jiǎn)單應(yīng)用Android觸控監(jiān)聽器來操作屏幕,雖然在實(shí)驗(yàn)中遇到了一
17、些困難,但還是受益良多。實(shí)驗(yàn)四 網(wǎng)絡(luò)訪問與服務(wù)一、實(shí)驗(yàn)?zāi)康?掌握Android網(wǎng)絡(luò)訪問方法。二、主要儀器設(shè)備及套數(shù)計(jì)算機(jī)三、實(shí)驗(yàn)內(nèi)容1. 了解手機(jī)WEB網(wǎng)站訪問編程,通過HttpResponse類,讀入網(wǎng)絡(luò)數(shù)據(jù)2. 通過網(wǎng)絡(luò)進(jìn)行數(shù)據(jù)訪問3. 了解數(shù)據(jù)庫(kù)使用四、程序代碼publicclass slide8_3 extends Activity Public Sting myhttpget(String url) throws ExceptionString out =null;Try HttpClient client=newDefaultHttpClient(); HttpGet reques
18、t=newHttpGet(url); HttpResponse request=client.execute(request); out=EntityUtils.toString(response.getEntity(); catch(IOException e) e.printStackTrace(); return out;Public String myhttppost(String url,String name,String value) Throw Eeception String out=null;try HttpClient client=newDefaultHttpClien
19、t(); HttpPost request=newHttpPost(url); List<NameValuePair>postParameters=newArrayList<NameValuePair>();postParameters.add(newBasicNameValuePair(name,value);UrlEncodedFormEntity=newEncodedFormEntity=newUrlEncodedFormEntity(postParameters);request.setEntity(formEntity);HttpResponse respon
20、se=client.execute(request); out=EntityUtils.toString(response.getEntity();catch(IOException e) e.printStackTrace(); return out;Overridepublic void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Final TextViewtextview=(TextView)findviewby
21、id(R.id. TextView01);FinalEditVieweditview=(EditView)findviewbyid(R.id. EditText1);finalEditText name=(EditText)findviewbyid(R.id. EditText2);finalEditText value=(EditText)findviewbyid(R.id. EditText3);Button btn=(Button)this.findviewbyid(R.id.Button1);btn.setOnClickListener(newButton.OnClickListene
22、r() Public void onclick(View v)Try textView.setText(myhttpget(editText.getText().toString()+”?” +name.getText().toString()+”=”+value.getText().toString();catch(Exception e) e.printStackTrace(); );Button btn2=(Button)this.findviewbyid(R.id.Button2);Btn2.setOnClickListener(newButton.OnClickListener()P
23、ublic void onclick(View v) TrytextView.setText(myhttppost(editText.getText().toString(),name.getText().toString(), value.getText().toString(); catch(Exception e) e.printStackTrace(); );五、實(shí)驗(yàn)結(jié)果Get:Post:六、實(shí)驗(yàn)小結(jié) 在這次試驗(yàn)中,我基本掌握了Android訪問網(wǎng)絡(luò)的基本方法,了解了手機(jī)WEB網(wǎng)站訪問編程,通過HttpResponse類,讀入網(wǎng)絡(luò)數(shù)據(jù),再通過網(wǎng)絡(luò)進(jìn)行數(shù)據(jù)訪問,最后還基本學(xué)會(huì)了數(shù)據(jù)庫(kù)使用
24、。實(shí)驗(yàn)五 Android平臺(tái)下手電應(yīng)用的設(shè)計(jì)開發(fā)一、實(shí)驗(yàn)?zāi)康?1.掌握Android項(xiàng)目中界面顯示的基本方法; 2.掌握OnTouchListener監(jiān)聽器的設(shè)計(jì)與使用 3.了解Android手機(jī)硬件API的調(diào)用方法。二、主要儀器設(shè)備及套數(shù)計(jì)算機(jī)三、實(shí)驗(yàn)內(nèi)容 1. 使用屏幕觸控 2. 調(diào)用相機(jī)的閃光點(diǎn)硬件,開啟手電功能 3. 暫不考慮橫屏切換四、程序代碼package cn.lee.handlight;import android.app.Activity;import android.hardware.Camera;import android.hardware.Camera.Paramet
25、ers;import android.os.Bundle;import android.os.Process;import android.view.View;import android.view.View.OnClickListener;import android.view.WindowManager;import android.widget.ToggleButton;public class HandLightActivity extends Activity implements OnClickListener private ToggleButton toggleButton;private Camera camera = Camera.open();/* Called when the activity is first created. */Overridepublic void onCreate(Bundle savedInstanceStat
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 莆田學(xué)院《空間分析與決策支持》2023-2024學(xué)年第二學(xué)期期末試卷
- 四川汽車職業(yè)技術(shù)學(xué)院《生物信息學(xué)(雙語(yǔ))》2023-2024學(xué)年第二學(xué)期期末試卷
- Unit 2 Different families Part A Let's talk Let's learn融合課(教學(xué)設(shè)計(jì))-2024-2025學(xué)年人教PEP版(2024)英語(yǔ)三年級(jí)上冊(cè)
- 山東女子學(xué)院《統(tǒng)計(jì)建模與軟件》2023-2024學(xué)年第二學(xué)期期末試卷
- 陜西警官職業(yè)學(xué)院《大學(xué)語(yǔ)文》2023-2024學(xué)年第二學(xué)期期末試卷
- 黑龍江農(nóng)業(yè)經(jīng)濟(jì)職業(yè)學(xué)院《工程測(cè)量》2023-2024學(xué)年第二學(xué)期期末試卷
- 河南建筑職業(yè)技術(shù)學(xué)院《生物統(tǒng)計(jì)與試驗(yàn)設(shè)計(jì)實(shí)驗(yàn)》2023-2024學(xué)年第二學(xué)期期末試卷
- 廣東技術(shù)師范大學(xué)《老年學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- Unit 5 Into the wild 單元教學(xué)設(shè)計(jì) -2024-2025學(xué)年高中英語(yǔ)外研版(2019)必修第一冊(cè)
- Unit 4 What can you do PB Let's learn (教學(xué)設(shè)計(jì))-2024-2025學(xué)年人教PEP版英語(yǔ)五年級(jí)上冊(cè)
- 術(shù)后鎮(zhèn)痛泵的使用與護(hù)理
- GB 19522-2024車輛駕駛?cè)藛T血液、呼氣酒精含量閾值與檢驗(yàn)
- 2024年成都新都投資集團(tuán)有限公司招聘筆試沖刺題(帶答案解析)
- 危險(xiǎn)預(yù)知訓(xùn)練表(KYT)
- 2024年湖南鐵路科技職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)技能測(cè)試題庫(kù)及答案解析
- 《書籍裝幀設(shè)計(jì)》 課件 項(xiàng)目1 走進(jìn)書籍裝幀設(shè)計(jì)
- ASTM標(biāo)準(zhǔn)全部目錄(中文版)
- 《汽車電氣設(shè)備構(gòu)造與維修》 第4版 課件 第3、4章 電源系統(tǒng)、發(fā)動(dòng)機(jī)電器
- 遼海版小學(xué)美術(shù)六年級(jí)下冊(cè)全冊(cè)教案
- 2023年南京市鼓樓區(qū)建寧路街道安監(jiān)辦招聘專職安全員考試真題及答案
- 鄉(xiāng)鎮(zhèn)精神衛(wèi)生工作總結(jié)
評(píng)論
0/150
提交評(píng)論