一、简答题 (每小题5分,4小题,共20分)
1、(1) android大众常用的五种布局(5分)
答:FrameLayout(框架布局),LinearLayout (线性布局),AbsoluteLayout(绝对布局),RelativeLayout(相对布局),TableLayout(表格布局)。
(2)两个Activity之间怎么传递数据?(5分)
答:基本数据类型可以通过. Intent 传递数据,extras.putDouble(key, value),intent.putExtras(extras)。
2、(1)请描述一下Intent 和Intent Filter(5分)
答:Intent和IntentFilter是Android和一种消息通信机制,可以让系统的组件之间进行通信。信息的载体就是Intent,它可以是一个要完成的动作请求,也可以一般性的消息广播,它可以由任意一个组件发出。消息,也就是Intent,最终也是要被组件来进行处理和消化。
(2)谈谈UI中, Padding和Margin有什么区别?(5分)
答:Padding 为内边框,指该控件内部内容,如文本/图片距离该控件的边距;Margin 为外边框,指该控件距离边父控件的边距
二、操作题(每题20分,共4题,共80分)
(1)用TextView和button及其属性实现在界面显示“Hello The Android World!”。
新建android项目如AI01,在项目的/AI01/src/com/example/ai01/MainActivity.java文件写下如下代码,注意包名!
package com.example.ai01;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
super.onCreate(savedInstanceState);
TextView textView = (TextView)findViewById(R.id.textView01);
Button button = (Button)findViewById(R.id.button01);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
在项目的/AI01/res/layout/activity_main.xml文件写下如下代码。
在项目的
/AI01/res/values/strings.xml
文件写下如下代码。
AI01
Hello world!
Settings
Hello The Android World!
I am a button!
运行效果如下。
(2)利用Intent及其方法和Activity实现如图调用拨号程序。
新建android项目如AI02,在项目的/AI02/src/com/example/ai02/MainActivity.java文件写下如下代码,注意包名!
package com.example.ai02;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView tvTelphone=null;
private Button btnCall=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvTelphone=(TextView)super.findViewById(R.id.telphone);
btnCall=(Button)super.findViewById(R.id.call);
btnCall.setOnClickListener(new OnClickListener(){
public void onClick(View v)
{
String Telphone=tvTelphone.getText().toString();
Uri uri=Uri.parse("tel:"+Telphone);
Intent intent=new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(uri);
MainActivity.this.startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
在项目的/AI02/res/layout/activity_main.xml文件写下如下代码。
在项目的
/AI02/AndroidManifest.xml
文件添加如下代码。
运行效果如下。