Android应⽤程序开发期末⼤作业(1)
⼀、简答题 (每⼩题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⽂件写下如下代码,注意包名!
ample.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) {
setContentView(R.layout.activity_main);
TextView textView = (TextView)findViewById(View01);          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().u.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 l.
int id = ItemId();
if (id == R.id.action_settings) {
return true;
}
OptionsItemSelected(item);
}
}
在项⽬的/AI01/res/layout/l⽂件写下如下代码。
<RelativeLayout xmlns:android="schemas.android/apk/res/android"    xmlns:tools="schemas.android/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="ample.ai01.MainActivity" >
<TextView
android:id="@+id/textView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>
<Button
android:id="@+id/button01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView01"
android:text="@string/button" />
</RelativeLayout>
在项⽬的/AI01/res/l⽂件写下如下代码。
安卓app开发用什么框架
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">AI01</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="hello">Hello The Android World!</string>
<string name="button">I am a button!</string>
</resources>
运⾏效果如下。
(2)利⽤Intent及其⽅法和Activity实现如图调⽤拨号程序。
新建android项⽬如AI02,在项⽬的/AI02/src/com/example/ai02/MainActivity.java⽂件写下如下代码,注意包名!
ample.ai02;
import android.app.Activity;
t.Intent;
import android.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) {
setContentView(R.layout.activity_main);
tvTelphone=(TextView)super.findViewById(lphone);          btnCall=(Button)super.findViewById(R.id.call);
btnCall.setOnClickListener(new OnClickListener(){
public void onClick(View v)
{
String Text().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().u.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 l.
int id = ItemId();
if (id == R.id.action_settings) {
return true;
}
OptionsItemSelected(item);
}
}
在项⽬的/AI02/res/layout/l⽂件写下如下代码。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。