Android应用程序开发期末大作业(1) - Go语言中文社区

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)用TextViewbutton及其属性实现在界面显示“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文件写下如下代码。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/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="com.example.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/values/strings.xml文件写下如下代码。
<?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文件写下如下代码,注意包名!

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文件写下如下代码。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/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="com.example.ai02.MainActivity" >

    <TextView  
        android:id="@+id/tel"  
        android:layout_width="match_parent"  
        android:layout_height="wrap_content" 
        android:text="请输入电话号码:" />  
  
    <EditText  
        android:id="@+id/telphone"  
        android:layout_width="match_parent"  
        android:layout_height="wrap_content"  
        android:layout_below="@+id/tel"
        android:ems="10" >
        
        <requestFocus />  
    </EditText>

    <Button
        android:id="@+id/call"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/telphone"
        android:text="呼叫" />

</RelativeLayout>
在项目的/AI02/AndroidManifest.xml文件添加如下代码。

<uses-permission android:name="android.permission.CALL_PHONE"/>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.ai02"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="17" />
    
    <uses-permission android:name="android.permission.CALL_PHONE"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            
        </activity>
        
    </application>

</manifest>
运行效果如下。






版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/Cai181191/article/details/78884934
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-06-27 21:54:49
  • 阅读 ( 998 )
  • 分类:Go应用

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢