android試卷A及答案_第1頁(yè)
android試卷A及答案_第2頁(yè)
android試卷A及答案_第3頁(yè)
android試卷A及答案_第4頁(yè)
android試卷A及答案_第5頁(yè)
已閱讀5頁(yè),還剩10頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、Android應(yīng)用試卷A一、選擇題(10分)1. 下列不是手機(jī)操作系統(tǒng)的是?(D)A. AndroidB. Window MobileC. Apple IPhone IOSD. windows vista2. 下列選項(xiàng)哪個(gè)不是Activity啟動(dòng)的方法?( B )A. startActivityB. goToActivityC. startActivityForResultD. startActivityFromChild3. 下列哪個(gè)不是Activity的生命周期方法之一?( B )A. onCreateB. startActivityC. onStartD. onResume4. 下列哪個(gè)

2、可做Android數(shù)據(jù)存儲(chǔ)?( A )A. SQliteB. MySqlC. OracleD. DB25. 下列哪個(gè)可做EditText編輯框的提示信息?( D )A. android:inputTypeB. android:textC. android:digitsD. android:hint二、真空題(20分)1. 為了使android適應(yīng)不同分辨率機(jī)型,布局時(shí)字體單位應(yīng)用sp,像素單位應(yīng)用sp和dip。2. 定義LinearLayout水平方向布局時(shí)至少設(shè)置的三個(gè)屬性:android:orientation,android:layout_width和android:layout_hei

3、ght。3. 設(shè)置ImageView控件為灰色的方法是:android:background=”#040” 。4. layout布局文件的命名不能出現(xiàn)字母大寫。5. 設(shè)置EditText只能輸入” 1234567890.+-*/%()”屬性:android:digits。6. 設(shè)置TextView字體的屬性是:android:textSize。三、簡(jiǎn)答題(30分)1. Android項(xiàng)目中的入口Activity怎么寫?如何注冊(cè)一般的Activity?(1) Android項(xiàng)目中的入口Activity:<?xml version="1.0" encoding="

4、;utf-8"?><manifest xmlns:android=" package="com.test" android:versionCode="1" android:versionName="1.0"> <application android:icon="drawable/icon" android:label="string/app_name"> <activity android:name=".WelcomeActiv

5、ity" android:label="string/app_name"> <intent-filter> <action android:name="ent.action.MAIN" /> <category android:name="ent.category.LAUNCHER" /> </intent-filter>(2) 注冊(cè)一般的Activity: </activity> <activity andr

6、oid:name=".test"/> </application> <uses-sdk android:minSdkVersion="6" /></manifest>2. 列舉通過(guò)Intent傳遞不同數(shù)據(jù)類型的方法(至少5個(gè))?Intent.addCategory(String category)Intetn.addFlags(int flags)Intent.equals(Object o)Intent.fillIn(Intent other,int flags)Intent.filterEquals(Inte

7、nt other)3. 請(qǐng)介紹下Android中常用幾種布局(至少3種,多一個(gè)加2分)?線性布局LinearLayout,相對(duì)布局RelativeLayout,表單布局TableLayout,幀布局FrameLayout,列表布局:listview,表格布局:gridview,絕對(duì)布局:absoluteLayout,標(biāo)簽布局:tablayout4. 闡述android:padding和android:layout_margin的異同?(1)不同點(diǎn):android:padding 是站在父View 的角度描述問(wèn)題,它規(guī)定它里面的內(nèi)容必須與這個(gè)父View 邊界的距離。android:layout_

8、margin 則是站在自己角度描述問(wèn)題,規(guī)定自己和其他(上下左右)的 View 之間的距離如同一級(jí)只有一個(gè)View,那么他的效果基本上就和padding一樣。(2)相同點(diǎn):如同一級(jí)只有一個(gè)View,那么android:layout_margin的效果基本上就和android:padding一樣5. 列舉TextView控件中的10個(gè)屬性?android:text android:hint android:textColor android:textSize android:bufferType android:maxLines android:lines android:layout_widt

9、h android:layout_height android:layout_gravity四、編程題(40分)1. 寫出按鈕和按鈕單擊事件(6分)布局文件 :main.xml<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" ><TextView

10、android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="計(jì)算你的標(biāo)準(zhǔn)體重" android:id="+id/title" android:textSize="20sp" android:layout_centerHorizontal="true" android:layout_marginTop="20dp" /><TextVi

11、ew android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="性別:" android:layout_below="+id/title" android:layout_marginTop="20dp" android:id="+id/sextitle"/><RadioGroupandroid:layout_width="wrap_cont

12、ent" android:layout_height="wrap_content" android:orientation="horizontal" android:id="+id/sexgroup" android:layout_below="+id/sextitle" android:checkedButton="+id/male"><RadioButton android:layout_width="wrap_content" android:la

13、yout_height="wrap_content" android:id="+id/male" android:text="男"/><RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="女" android:id="+id/female"/></RadioGroup><Tex

14、tView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="身高:" android:layout_below="+id/sexgroup" android:layout_marginTop="20dp" android:id="+id/heighttitle"/><EditText android:layout_width="2

15、00dp" android:layout_height="wrap_content" android:layout_below="+id/heighttitle" android:id="+id/height"/><Buttonandroid:layout_width="wrap_content" android:layout_height="wrap_content" android:text="計(jì)算" android:layout_below=&qu

16、ot;+id/height" android:id="+id/btn" android:layout_marginTop="20dp" android:paddingLeft="20dp" android:paddingRight="20dp"/></RelativeLayout>Activity:MainActivity.javaimport android.app.MainActivity;import android.app.AlertDialog;import android.c

17、ontent.DialogInterface;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.RadioButton;public class MainActivity extends Activity /* Called when the activity is first created. */

18、Override public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.main); Button btn = (Button)findViewById(R.id.btn); btn.setOnClickListener(btnClickListener); OnClickListener btnClickListener = new OnClickListener() public void onClick(View v) / TO

19、DO Auto-generated method stubRadioButton male = (RadioButton)findViewById(R.id.male);/sex=1 代表男性/sex=2 代表女性int sex = male.isChecked()?1:2;EditText et = (EditText)findViewById(R.id.height);/得到用戶輸入的身高float height = Float.parseFloat(et.getEditableText().toString();float weight = getWeight(sex, height);

20、new AlertDialog.Builder(Main.this).setTitle("體重").setMessage("您的標(biāo)準(zhǔn)體重為"+weight).setPositiveButton("確定", new DialogInterface.OnClickListener() public void onClick(DialogInterface dialog, int which) ).show();/此方法用來(lái)計(jì)算標(biāo)準(zhǔn)體重public float getWeight(int sex,float height)float wei

21、ght = 0.0f;if (sex=1) weight = (height - 80) * 0.7f; else weight = (height - 70) * 0.6f;return Math.round(weight);2. 寫出按鈕和按鈕單擊后跳轉(zhuǎn)到另一個(gè)Activity(6分)布局文件 :main.xml(寫出完整控件即可)<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:orientation="ver

22、tical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#fff" ><TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="string/welcome_title" andro

23、id:layout_gravity="center" android:textSize="24sp" android:textColor="#000" android:layout_marginTop="10dip" android:layout_marginBottom="10dip" android:textStyle="bold" /> <ImageView android:layout_width="wrap_content" andr

24、oid:layout_height="140dip" android:background="drawable/bg_welcome" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" /> <Button android:id="+id/wel_btn1" android:layout_width="140dip" android:layout_height="wr

25、ap_content" android:text="string/welcome_btn1" android:layout_gravity="center_horizontal" android:layout_marginTop="10dip" android:padding="1dip" /> <Button android:id="+id/wel_btn2" android:layout_width="140dip" android:layout_h

26、eight="wrap_content" android:text="string/welcome_btn2" android:layout_gravity="center_horizontal" android:layout_marginTop="10dip" android:padding="1dip" /> <Button android:id="+id/wel_btn3" android:layout_width="140dip" an

27、droid:layout_height="wrap_content" android:text="string/welcome_btn3" android:layout_gravity="center_horizontal" android:layout_marginTop="10dip" android:padding="1dip" /> <TextView android:layout_width="wrap_content" android:layout_h

28、eight="wrap_content" android:text="string/welcome_address" android:layout_gravity="right" android:textSize="15sp" android:textColor="#000" android:layout_marginRight="10dip" android:layout_marginTop="30dip" android:textStyle="

29、;italic" /></LinearLayout>Activity:MainActivity.java(跳轉(zhuǎn)目標(biāo)OtherActivity.java)(寫出關(guān)鍵代碼即可)import junit.framework.MainActivity;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.

30、widget.Button;public class MainActivity extends Activity Button wel_btn1; Button wel_btn2; Button wel_btn3; /* Called when the activity is first created. */ Override public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.main); wel_btn1=(Button)fi

31、ndViewById(R.id.wel_btn1); wel_btn2=(Button)findViewById(R.id.wel_btn2); wel_btn3=(Button)findViewById(R.id.wel_btn3); wel_btn1.setOnClickListener(onClickListener); wel_btn2.setOnClickListener(onClickListener); wel_btn3.setOnClickListener(onClickListener); OnClickListener onClickListener=new OnClick

32、Listener() public void onClick(View v) / TODO Auto-generated method stubMainActivity.this.finish();Intent intent=new Intent(MainActivity.this,OtherActivity.class);startActivity(intent);3. 寫出加1 和 減1的程序主要代碼(6分)布局文件 :main.xml  <?xml version="1.0" encoding="utf-8" ?> - <

33、;LinearLayout xmlns:android="" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:te

34、xt="每天運(yùn)動(dòng):" android:gravity="left" android:textSize="18sp" />   <Button android:id="+id/add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="drawable/btn_add" android:textSize

35、="24sp" />  <TextView android:id="+id/result" android:layout_width="90dip" android:layout_height="wrap_content" android:textSize="18sp" android:background="#fff" />  <Button android:id="+id/less" android:layo

36、ut_width="wrap_content" android:layout_height="wrap_content" android:background="drawable/btn_less" android:textSize="24sp" />   </LinearLayout>Activity:MainActivity.javaimport android.app.MainActivity;import android.os.Bundle;import android.view

37、.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;public class MainActivity extends Activity TextView textView;int temp = 0; /* Called when the activity is first created. */ Override public void onCreate(Bundle savedInstanceState) super.onCrea

38、te(savedInstanceState); setContentView(R.layout.button); Button addButton = (Button) findViewById(R.id.add); addButton.setOnClickListener(onClickListener); Button lessButton = (Button) findViewById(R.id.less); lessButton.setOnClickListener(onClickListener); textView = (TextView) findViewById(R.id.re

39、sult); textView.setText("0分鐘/天"); OnClickListener onClickListener = new OnClickListener() public void onClick(View v) / TODO Auto-generated method stubif(v.getId() = R.id.add)temp += 5;textView.setText(temp+"分鐘/天");else if(v.getId() = R.id.less)temp -= 5;textView.setText(temp+&qu

40、ot;分鐘/天");4. 寫出按鈕點(diǎn)擊和非點(diǎn)擊狀態(tài)圖片切換的那個(gè)btn_login.xml文件代碼(6分)(圖片:btn_login_nor.png,btn_login_on.png)<?xml version="1.0" encoding="UTF-8"?><selector xmlns:android=" <item android:state_pressed="true" android:drawable="drawable/ btn_login_nor " /&g

41、t; <item android:drawable="drawable/ btn_login_on" /></selector>5. 只寫出猜紙牌游戲中的點(diǎn)擊第一張進(jìn)行猜牌的功能代碼?(6分)布局文件 :main.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:orientation="vertical" android:layout_width=&quo

42、t;fill_parent" android:layout_height="fill_parent" ><TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="猜猜看紅心A是哪一張?" android:textSize="20sp" android:layout_marginTop="20dp" android:layo

43、ut_marginLeft="20dp" android:id="+id/result" /><LinearLayout xmlns:android=" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="60dp" android:layout_

44、marginLeft="20dp" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="drawable/p04" android:id="+id/img1" /> <ImageView android:layout_width="wrap_content" android:layout_height=&qu

45、ot;wrap_content" android:src="drawable/p04" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:id="+id/img2" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:s

46、rc="drawable/p04" android:id="+id/img3" /></LinearLayout><Buttonandroid:layout_width="wrap_content" android:layout_height="wrap_content" android:text="再玩一次" android:layout_marginTop="80dp" android:layout_gravity="center" android:paddingLeft="30dp" android:paddingRight="30dp" android:id="+id/btn"/></LinearLayout>Activity:MainActivity.javaimport java.util.Arrays;import java.util.Collections;import ja

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝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ù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論