




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
目錄實驗一Android系統(tǒng)環(huán)境搭建 1實驗二Activity運用實驗 4實驗三android應用UI設計〔一〕 5實驗三android應用UI設計〔二〕 7局部參考答案 9
實驗一Android系統(tǒng)環(huán)境搭建一、目的與要求1.掌握Android環(huán)境的搭建。2.學會Java、eclipse、AndroidSDK以及ADT的安裝與環(huán)境變量設置。3.學會在線更新SDK。4.掌握離線安裝SDK的方法。二、實驗內容1.安裝JDK,SE6.0以上版本。⑴訪問以下下載JDK。⑵配置環(huán)境變量:安裝J2SDK以后,假設需要在cmd下使用Java命令和編譯、運行程序,可以配置環(huán)境變量:新建環(huán)境變量JAVA_HOME,右擊“我的電腦〞—>“屬性〞—>“高級〞—>“環(huán)境變量〞,如圖1-1所示:圖1-1⑶測試JDK安裝成功與否:編寫test.java文件,運行。要求:請將安裝的目錄與環(huán)境變量的配置圖粘到后面的空白頁上。并將test.java在運行結果粘上。2.安裝eclipse。訪問以下:///downloads/下載。選擇Windows平臺“EclipseIDEforJavaEEDevelopers〞下載,下載完成后,找到下載的壓縮包“eclipse-java-indigo-SR2-win32.zip〞,Eclipse無須安裝程序,解壓此壓縮文件到目標文件即可。要求:請將安裝的目錄與eclipse環(huán)境的界面圖粘到后面的空白頁上。3.安裝AndroidSDK[1]訪問以下網(wǎng)址下載:[2]在線安裝SDK:翻開SDKManager,如圖1-2、1-3所示。圖1-2圖1-3[3]離線安裝:首先下載SDK的安裝包,“android-sdk_r16-windows.zip〞〔安裝工具〕解壓到目錄,如我的目錄D:\TDDOWNLOAD\android-sdk_r16-windows\android-sdk-windows,然后新建以下幾個文件夾:platforms,docs,samples,usb_driver,market_licensing。接著翻開下載工具,下載以下內容:ows.zip
要求:請將安裝的目錄與SDK在界面圖粘到后面的空白頁上。4.安裝ADT[1]首先啟動Eclipse,選擇Help->InstallNewSoftware,翻開Eclipse的插件安裝頁面。[2]單擊Add按鈕,彈出“AddRepository〞對話框,在Name中輸入:ADT,在Location中輸入:,單擊OK按鈕后,Eclipse會自動搜索可安裝的插件。[3]此時Eclipse會搜索指定URI的資源,如果搜索無誤,會出現(xiàn):DevelopTools的復選框,選中復選框,點擊“Next〞按鈕。再點擊finish按鈕[4]整個安裝過程會持續(xù)幾分鐘,安裝結束后會出現(xiàn)Eclipse重啟提示界面,。建議選擇“RestartNow〞按鈕重新啟動Eclipse,使ADT插件生效。[5]在ADT插件安裝完畢且重啟Eclipse之后,進入配置Android開發(fā)環(huán)境的最后一步,設置AndroidSDK的位置。首先選擇Windows->Preference命令翻開Eclipse的配制界面,然后在SDKLocation中輸入AndroidSDK的保存路徑,最后單擊OK按鈕使配置生效。要求:請將安裝ADT后的eclipse界面圖粘到后面的空白頁上。
實驗二Activity運用實驗一、目的與要求1.熟悉Activity與Intent的使用。2.掌握Activity啟動另一個Activity的方法。3.會使用Intent對象進行Activity間意圖的傳達。二、實驗內容1.編一Android應用程序TestActivity01,使用MainActivity,啟動另一個OtherActivity。MainActivity主界面上只有一個按鈕。OtherActivity上只有一個TextView組件。要求:請將工程中的MainActivity.java,OtherActivity.java以及對應的xml文件源碼附上。同時將運行的界面圖粘上。2.編一Android應用程序TestActivity02,使用MainActivity,啟動另一個OtherActivity。MainActivity主界面上只有一個按鈕。OtherActivity上只有一個TextView組件。要將MainActivity中的數(shù)據(jù)“中國〞通過Intent對象傳到OtherActivity上顯示。要求:請將工程中的MainActivity.java,OtherActivity.java以及對應的xml文件源碼附上。同時將運行的界面圖粘上。
實驗三android應用UI設計〔一〕一、目的與要求1.熟悉TextView、Button、ImageView、LinearLayout、TabelLayout、RelativeLayout、FrameLayout、AlertDialog對話框。2.掌握以上UI設計元素的根本功能和用法。3.掌握UI設計的根本方法。二、實驗內容〔一〕實現(xiàn)一個如圖3.1所示的UI界面1.布局分析:最外層是縱向的線性布局〔LinearLayout,android:orientation="vertical"〕,包含了三個布局,橫向的線性布局〔四列〕、表格布局〔TableLayout,三行三列〕、縱向的線性布局〔四行〕。2.在res\layout文件夾下的MyLayout.xml中實現(xiàn)。3.布局內的控件為TextView要求:請將工程中的java源文件以及對應的xml文件源碼附上。同時將運行的界面圖粘上。圖3.1布局嵌套圖3.2多輸入對話框
〔二〕實現(xiàn)一個如圖3.2所示的多輸入框的對話框1.要求使用LinearLayout布局、TextView、EditText控件各兩個。2.要求點擊按鈕后有對應的輸出〔用Toast控件、TextView控件以及Logcat窗口輸出都可以〕。要求:請將工程中的java源文件以及對應的xml文件源碼附上。同時將運行的界面圖粘上。
實驗三android應用UI設計〔二〕一、目的與要求1.熟悉Menu、Toast、Notification等UI元素。2.掌握以上UI設計元素的根本功能和用法。3.掌握以上UI設計的根本方法與框架。4.了解PendingIntent對象與Notification間的關系。5.了解根本的ListViewAdapter的設置與作用。二、實驗內容〔一〕在ListActivity中實現(xiàn)ContextMenu。1.編寫上下文菜單實現(xiàn)如下功能:1〕用ArrayAdapter實現(xiàn)一個ListView,如圖4.1所示。2〕在每一表項上長按后,彈出上下文菜單,如圖4.2所示。2.提示如下:1〕MainActivity從ListActivity派生而來〔便于對List在操作〕。2〕在onCreate中使用simpleShowList()方法顯示列表,并實現(xiàn)該方法。3〕為所有列表項注冊上下文菜單registerForContextMenu(getListView())。4〕不對上下文菜單做事件響應〔代碼中僅表達框架就可以〕。要求:請將工程中的java源文件以及對應的xml文件源碼附上。同時將運行的界面圖粘上。圖4.1列表顯示圖4.2與列表相關的上下文菜單
〔二〕Notification1.實現(xiàn)一個如圖4.3如所的Notification。在點擊“發(fā)起通知〞按鈕后,在狀態(tài)欄出現(xiàn)圖標與“我的通知〞信息。2.提示:1〕需要創(chuàng)立一個PendingIntent對象。該對象由Android系統(tǒng)負責維護,因此,在應用程序關閉后,該對象仍然不會被釋放。2〕點擊通知后由Intent(MainActivity.this,
NActivity.class)起動下一個Activity。3〕NActivity僅顯示一個TextView就可以,其內容為“Notification啟動成功〞。要求:請將工程中的java源文件以及對應的xml文件源碼附上。同時將運行的界面圖粘上。圖4.3通知的界面
局部參考答案實驗3參考答案〔一〕1、布局配置文件main.xml<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="://schemas.android/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="4">
<TextView
android:text="red"
android:textSize="7pt"
android:textColor="#000000"
android:background="#ff0000"
android:gravity="center_vertical|center_horizontal"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
/>
<TextView
android:text="green"
android:textSize="7pt"
android:textColor="#000000"
android:background="#00ff00"
android:gravity="center_vertical|center_horizontal"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
/>
<TextView
android:text="blue"
android:textSize="7pt"
android:textColor="#000000"
android:background="#0000ff"
android:gravity="center_vertical|center_horizontal"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
/>
<TextView
android:text="yellow"
android:textSize="7pt"
android:textColor="#000000"
android:background="#ffff00"
android:gravity="center_vertical|center_horizontal"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<TableLayoutxmlns:android="://schemas.android/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<!--拉伸指定列來填滿父控件-->
<TableRow
android:id="@+id/row1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:text="@string/row1_column1"
android:gravity="center_horizontal"
android:padding="3dip"
/>
<TextView
android:text="@string/row1_column2"
android:gravity="center_horizontal"
android:padding="3dip"
/>
<TextView
android:text="@string/row1_column3"
android:gravity="center_horizontal"
android:padding="3dip"
/>
</TableRow>
<TableRow
android:id="@+id/row2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:text="@string/row2_column1"
android:gravity="center_horizontal"
android:padding="3dip"
/>
<TextView
android:text="@string/row2_column2"
android:gravity="center_horizontal"
android:padding="3dip"
/>
<TextView
android:text="@string/row2_column3"
android:gravity="center_horizontal"
android:padding="3dip"
/>
</TableRow>
<TableRow
android:id="@+id/row3"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:text="@string/row3_column1"
android:gravity="center_horizontal"
android:padding="3dip"
/>
<TextView
android:text="@string/row3_column2"
android:gravity="center_horizontal"
android:padding="3dip"
/>
<TextView
android:text="@string/row3_column3"
android:gravity="center_horizontal"
android:padding="3dip"
/>
</TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="2">
<TextView
android:text="red"
android:textSize="7pt"
android:textColor="#000000"
android:background="#ff0000"
android:gravity="center_vertical|center_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
/>
<TextView
android:text="green"
android:textSize="7pt"
android:textColor="#000000"
android:background="#00ff00"
android:gravity="center_vertical|center_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
/>
<TextView
android:text="blue"
android:textSize="7pt"
android:textColor="#000000"
android:background="#0000ff"
android:gravity="center_vertical|center_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
/>
<TextView
android:text="yellow"
android:textSize="7pt"
android:textColor="#000000"
android:background="#ffff00"
android:gravity="center_vertical|center_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
/>
</LinearLayout></LinearLayout>===================================2、string.xml文件<?xmlversion="1.0"encoding="utf-8"?><resources>
<stringname="hello">HelloWorld,ComplicateLayout!</string>
<stringname="app_name">Layout04</string>
<stringname="row1_column1">學號</string>
<stringname="row1_column2">姓名</string>
<stringname="row1_column3">性別</string>
<stringname="row2_column1">10101</string>
<stringname="row2_column2">李剛</string>
<stringname="row2_column3">男</string>
<stringname="row3_column1">10102</string>
<stringname="row3_column2">文靜</string>
<stringname="row3_column3">女</string></resources>=================================3、Android工程清單文件<?xmlversion="1.0"encoding="utf-8"?><manifestxmlns:android="://schemas.android/apk/res/android"
package="hw.layout04"
android:versionCode="1"
android:versionName="1.0">
<uses-sdkandroid:minSdkVersion="8"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity
android:name="plicateLayout"
android:label="@string/app_name">
<intent-filter>
<actionandroid:name="ent.action.MAIN"/>
<categoryandroid:name="ent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application></manifest>==================================4、Java源程序packagehw.layout04;importandroid.app.Activity;importandroid.os.Bundle;publicclassComplicateLayoutextendsActivity{
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}}〔二〕需要一個布局01<?xmlversion="1.0"encoding="utf-8"?>02<LinearLayoutxmlns:android="://schemas.android/apk/res/android"03android:layout_width="fill_parent"04android:layout_height="fill_parent"05android:orientation="vertical">07<TextView08android:id="@+id/textView1"09android:layout_width="wrap_content"10android:layout_height="wrap_content"11android:text="姓名"/>13<EditText14android:id="@+id/editTextName"15android:layout_width="match_parent"16android:layout_height="wrap_content">18<requestFocus/>19</EditText>21<TextView22android:id="@+id/textView2"23android:layout_width="wrap_content"24android:layout_height="wrap_content"25android:text="號碼"/>27<EditText28android:id="@+id/editTextNum"29android:layout_width="match_parent"30android:layout_height="wrap_content"/>32</LinearLayout>//代碼01protectedvoidshowAddDialog(){03LayoutInflaterfactory=LayoutInflater.from(this);04finalViewtextEntryView=factory.inflate(R.layout.dialog,null);05finalEditTexteditTextName=(EditText)textEntryView.findViewById(R.id.editTextName);06finalEditTexteditTextNumEditText=(EditText)textEntryView.findViewById(R.id.editTextNum);07AlertDialog.Builderad1=newAlertDialog.Builder(FriendActivity.this);08ad1.setTitle("增加聯(lián)系人:");09ad1.setIcon(android.R.drawable.ic_dialog_info);10ad1.setView(textEntryView);11ad1.setPositiveButton("是",newDialogInterface.OnClickListener(){12publicvoidonClick(DialogInterfacedialog,inti){14Log.i("111111",editTextName.getText().toString());15PersonServicepersonService=newPersonService(16FriendActivity.this.getBaseContext());17Personperson=newPerson();18person.setName(editTextName.getText().toString());19person.setPhoneNumber(editTextNumEditText.getText().toString());20personService.save(person);22}23});24ad1.setNegativeButton("否",newDialogInterface.OnClickListener(){25publicvoidonClick(DialogInterfacedialog,inti){27}});ad1.show();//顯示對話框}實驗4參考答案〔一〕//注冊上下文菜單PublicclassSampleContextMenuActivityextendsListActivity{privatestaticfinalStringTAG="SampleContextMenuActivity";@OverrideProtectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);//顯示列表simpleShowList();//為所有列表項注冊上下文菜單this.registerForContextMenu(getListView());}PrivatevoidsimpleShowList(){//listitemString[]files=newString[]{"文件1","文件2","文件3","文件4"};//simplearrayadapterArrayAdapter<String>adapter=newArrayAdapter<String>(this,android.R.layout.simple_list_item_1,files);//setadapterthis.setListAdapter(adapter);Log.v(TAG,"showsimplelist");}}//生成上下文菜單@Override
publicvoidonCreateContextMenu(ContextMenumenu,Viewv,
ContextMenuInfomenuInfo){
Log.v(TAG,"populatecontextmenu");
//setcontextmenutitle
menu.setHeaderTitle("文件操作");
//addcontextmenuitem
menu.add(0,1,Menu.NONE,"發(fā)送");
menu.add(0,2,Menu.NONE,"標記為重要");
menu.add(0,3,Menu.NONE,"重命名");
menu.add(0,4,Menu.NONE,"刪除");
}//響應上下文菜單項@Override
publicbooleanonContextItemSelected(MenuItemitem){
//得到當前被選中的item信息
AdapterContextMenuInfomenuInfo=(Adap
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 居間介紹合同協(xié)議書
- 《中文基礎語法中的同義詞辨析與用法講解》
- 企業(yè)團隊建設與激勵指南
- 麥當勞供應鏈研究
- 財務收支與利潤分析表
- 2025年拉薩貨運從業(yè)資格證考試模擬考試
- 工程施工合伙合同
- 2025年梧州道路貨運從業(yè)資格證考試
- 店面房屋買賣合同
- 商業(yè)地產項目策劃、開發(fā)及運營規(guī)范
- 深圳中考自主招生簡歷
- 壽光金遠東變性淀粉有限公司年產2萬噸乳酸、丙交酯、聚乳酸項目環(huán)境影響報告表
- 美術社團活動記錄
- 醫(yī)療機構注銷登記申請書
- GB/T 678-2023化學試劑乙醇(無水乙醇)
- 影視鑒賞-第一章-認識電影-課件
- 船舶塢修廠修工程單審批稿
- 教科版小學科學三年級上冊《空氣》單元解讀與試教課件
- 電機學同步電機-全套課件
- 公路工程施工安全管理及其實例
- 教科版高中信息技術(2019)必修一全冊教案
評論
0/150
提交評論