Android应用程序开发期末大作业(1)

2023-05-16

一、简答题 (每小题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>
运行效果如下。






本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android应用程序开发期末大作业(1) 的相关文章

随机推荐

  • 【Vue】postman汉化教程 保姆级教程 包教会

    下载链接 xff1a Win64 Win32 历史版本下载 请把下面链接的 34 版本号 34 替换为指定的版本号 xff0c 例如 xff1a 8 8 0 版本链接Windows32位https dl pstmn io download
  • 操作系统实验——进程与线程

    目录 1 使用GCC xff08 1 xff09 参数 xff08 2 xff09 自定义头文件 xff08 3 xff09 makefile脚本 xff08 4 xff09 gdb调试 2 进程 xff08 1 xff09 新建进程 xf
  • 串口应用(USART)

    串行口应用 1 USART介绍 通用同步异步收发器 USART 提供了一种灵活的方法与使用工业标准NRZ异步串行数据格式的 外部设备之间进行全双工数据交换 USART利用分数波特率发生器提供宽范围的波特率选择 它支持同步单向通信和半双工单线
  • cpp-httplib 避免阻塞主线程, c++封装httplib,httplib面向对象开发

    目录 说明 前言原生的httplib会阻塞你的主线程解决httplib阻塞主线程的问题BashController 面向对象风格使用httplib自定义controller MyController h文件自定义controller Tes
  • 数据结构——结构体的5种定义方式及对比

    以下仅为定义结构体的方式 xff0c 具体使用在后续的文章中介绍 span class token macro property span class token directive hash span span class token d
  • 【C++】STL应用(详解)

    一 泛型程序与STL1 泛型程序设计的基本概念2 STL简介 二 迭代器1 输入流迭代器2 输出流迭代器 三 STL应用1 撰写自己的算法和函数 xff0c 结合容器和迭代器解决序列变换 xff08 如取反 平方 立方 xff09 xff0
  • 模块学习(二)——MPU6050

    去年电赛备赛期间 xff0c 学的STM32标准库 xff0c 那一整个繁琐直接给我劝退了 xff0c 当时学习MPU6050时就非常痛苦 xff0c 代码也看不懂 xff0c 无非抄来抄去 xff0c 然后就是编译 xff0c 改错 xf
  • 【嵌入式面试题】常见的面试题梳理一

    注 xff1a 看面试题时 xff0c 主要应该以学习为主 xff0c 面试题有些基本上是我们编程时会遇上的问题 xff0c 通过学习面试题会提升我们的编程意识和解决一些日常我们编程所遇到的问题 xff0c 看完这篇面试题后 xff0c 希
  • 使用Python+openpyxl实现导出自定义样式的Excel文件

    之前项目中的导出Excel文件操作都是在前端完成的 xff0c 项目是由vue 43 vite构建的 xff0c 效果还不错的 xff0c 所需依赖包如下所示 npm i xlsx 64 0 18 5 npm i xlsx style vi
  • 【嵌入式面试题】常见面试题梳理二

    注 xff1a 看面试题时 xff0c 主要应该以学习为主 xff0c 面试题有些基本上是我们编程时会遇上的问题 xff0c 通过学习面试题会提升我们的编程意识和解决一些日常我们编程所遇到的问题 xff0c 看完这篇面试题后 xff0c 希
  • 【嵌入式面试题】常见面试题梳理三

    注 xff1a 看面试题时 xff0c 主要应该以学习为主 xff0c 面试题有些基本上是我们编程时会遇上的问题 xff0c 通过学习面试题会提升我们的编程意识和解决一些日常我们编程所遇到的问题 xff0c 看完这篇面试题后 xff0c 希
  • 【嵌入式面试题】常见面试题梳理四

    注 xff1a 看面试题时 xff0c 主要应该以学习为主 xff0c 面试题有些基本上是我们编程时会遇上的问题 xff0c 通过学习面试题会提升我们的编程意识和解决一些日常我们编程所遇到的问题 xff0c 看完这篇面试题后 xff0c 希
  • 【嵌入式面试题】常见面试题梳理五

    注 xff1a 看面试题时 xff0c 主要应该以学习为主 xff0c 面试题有些基本上是我们编程时会遇上的问题 xff0c 通过学习面试题会提升我们的编程意识和解决一些日常我们编程所遇到的问题 xff0c 看完这篇面试题后 xff0c 希
  • 【嵌入式面试题】常见面试题梳理六

    注 xff1a 看面试题时 xff0c 主要应该以学习为主 xff0c 面试题有些基本上是我们编程时会遇上的问题 xff0c 通过学习面试题会提升我们的编程意识和解决一些日常我们编程所遇到的问题 xff0c 看完这篇面试题后 xff0c 希
  • 我的创作一周年纪念日--收获与成长与展望

    机缘 2022年10月11日 xff0c 是我创作的一周年纪念日 xff0c 1年前 xff0c 刚到大三的我开启了我的创作之旅 xff0c 那个时候 xff0c 我选择重新学习C语言和数据结构 xff0c 将我的基础在进行巩固 在那个时候
  • 【Linux】特别篇--SMBus 协议

    Linux 特别篇 SMBus 协议 一 SMBus 简介二 SMBus 与 I2C 区别三 SMBus协议分析3 1 符号含义3 2 SMBus Quick Command3 3 SMBus Receive Byte3 4 SMBus S
  • 【Linux】特别篇--GNU C编译器扩展语法

    前言 xff1a 本章是我参考 嵌入式C语言自我修养 的GUN C编译器扩展语法这一章 xff0c 对其中的内容进行了摘录 总结与归纳 xff0c 并写了一些关于自己的理解 xff0c 这边还是推荐大家去购买原作的 xff0c 因为里面用通
  • 【ROS】机械人开发一--树莓派安装ubuntu18.04

    前言 xff1a 安装了一天的树莓派系统 xff0c 遇到了很多坑 xff0c 这里将教程详细分享一下 xff0c 方便大家快速的安装系统 目录 一 操作环境硬件软件 二 资源下载链接三 具体步骤烧入修改镜像文件问题修改重启时间PC端使用x
  • 【ROS】机械人开发二--ROS环境安装

    机械人开发二 ROS环境安装 一 运行环境二 ROS melodic安装2 1 设置软件源2 2 设置密钥2 3 安装ROS2 4 环境设置2 5 安装ROS的依赖环境2 6 初始化rosdep 三 建立工作空间测试 一 运行环境 树莓派4
  • Android应用程序开发期末大作业(1)

    一 简答题 每小题5分 xff0c 4小题 xff0c 共20分 1 1 android大众常用的五种布局 xff08 5分 xff09 答 xff1a FrameLayout 框架布局 xff0c LinearLayout 线性布局 xf