实验报告2.docx

上传人:b****5 文档编号:6634890 上传时间:2023-01-08 格式:DOCX 页数:34 大小:1.85MB
下载 相关 举报
实验报告2.docx_第1页
第1页 / 共34页
实验报告2.docx_第2页
第2页 / 共34页
实验报告2.docx_第3页
第3页 / 共34页
实验报告2.docx_第4页
第4页 / 共34页
实验报告2.docx_第5页
第5页 / 共34页
点击查看更多>>
下载资源
资源描述

实验报告2.docx

《实验报告2.docx》由会员分享,可在线阅读,更多相关《实验报告2.docx(34页珍藏版)》请在冰豆网上搜索。

实验报告2.docx

实验报告2

实验名称:

实验二UI设计

一、实验内容

1、TextView的使用。

设计字体属性(颜色、字号等)、超连接和跑马灯效果,运行结果:

 

2、设计如下界面,包括一个最大长度为30、输入文本类型为数字、有提示信息的单行文本框EditText,一个多行文本框和下拉列表。

运行结果:

3、请使用单选按钮设计一个背景颜色改变功能,让用户可通过单选按钮按预先设置的4种颜色(如红、绿、蓝、黄等)依次循环改变背景色。

用户选取时,利用Toast消息提示用户当前背景色并将结果立即应用到Layout组件。

4、设计如下界面,包括图片按钮、复选按钮、单选按钮、普通按钮,单击按钮弹出对话框,运行效果如下:

初始界面单击图片按钮

单击复选按钮确定单击单选按钮确定

5、设计如下界面完成BMI体重计算。

提示:

BMI计算方法。

doubleBMI=weight/(height*height);

其中,体重单位为公斤,身高单位为厘米。

当BMI>25超重,BMI<20超轻,20

6、完成简单的四则运算。

提示:

取得文本框输入内容:

Stringinfo=edit.getText().toString();

 

二、实验步骤及结果

1.

①字体属性(颜色、字号等)和跑马灯效果

程序代码:

activity_main.xml

xmlversion="1.0"encoding="utf-8"?

>

android="

xmlns:

app="

xmlns:

tools="

android:

layout_width="match_parent"

android:

layout_height="match_parent"tools:

context="firstandroidapp_by150104050020.firstapp.MainActivity">

android:

id="@+id/textview"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="FirstAndroidApp_by150********0郑凯峰"

android:

textColor="#404040"

android:

textSize="25dp"

android:

typeface="serif"

android:

singleLine="true"

android:

ellipsize="marquee"

android:

marqueeRepeatLimit="marquee_forever"

app:

layout_constraintBottom_toBottomOf="parent"

app:

layout_constraintLeft_toLeftOf="parent"

app:

layout_constraintRight_toRightOf="parent"

app:

layout_constraintTop_toTopOf="parent"/>

MainActivity.java

packagefirstandroidapp_by150104050020.firstapp;

importandroid.support.v7.app.AppCompatActivity;

importandroid.os.Bundle;

importandroid.widget.TextView;

Importstaticfirstandroidapp_by150104050020.firstapp.R.id.textview;

publicclassMainActivityextendsAppCompatActivity{

@Override

protectedvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

TextViewtv=(TextView)findViewById(textview);

tv.setSelected(true);

}

}

运行效果:

②超链接效果

程序代码:

activity_main.xml

xmlversion="1.0"encoding="utf-8"?

>

android="

xmlns:

app="

xmlns:

tools="

android:

layout_width="match_parent"

android:

layout_height="match_parent"tools:

context="firstandroidapp_by150104050020.firstapp.MainActivity">

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text=""

android:

autoLink="web"

app:

layout_constraintBottom_toBottomOf="parent"

app:

layout_constraintLeft_toLeftOf="parent"

app:

layout_constraintRight_toRightOf="parent"

app:

layout_constraintTop_toTopOf="parent"/>

运行效果:

2.

程序代码:

activity_main.xml

xmlversion="1.0"encoding="utf-8"?

>

android="

xmlns:

app="

xmlns:

tools="

android:

layout_width="match_parent"

android:

layout_height="match_parent"

tools:

context="firstandroidapp_by150104050020.myapplication.MainActivity">

xmlns:

android="

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

layout_gravity="center">

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="单行文本框"/>

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

background="#EEE8CD"

android:

hint="请输入数字!

"

android:

singleLine="true"

android:

maxLength="30"

android:

numeric="integer"/>

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="多行文本框"/>

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

background="#EEE8CD"/>

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="下拉列表"/>

android:

id="@+id/spinner"

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"

android:

entries="@array/spinner1"/>

array.xml

xmlversion="1.0"encoding="utf-8"?

>

English

Chinese

French

Korean

Japanese

MainActivity.java

packagefirstandroidapp_by150104050020.myapplication;

importandroid.support.v7.app.AppCompatActivity;

importandroid.os.Bundle;

publicclassMainActivityextendsAppCompatActivity{

@Override

protectedvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

}

 

运行效果:

3.

程序代码:

activity_main.xml

xmlversion="1.0"encoding="utf-8"?

>

android="

xmlns:

app="

xmlns:

tools="

android:

layout_width="match_parent"

android:

layout_height="match_parent"

tools:

context="firstandroidapp_by150104050020.myapplication.MainActivity">

xmlns:

android="

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

layout_gravity="center">

android:

id="@+id/button"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

gravity="center"

android:

text="改变当前背景颜色"

android:

textSize="25dp"/>

MainActivity.java

packagefirstandroidapp_by150104050020.myapplication;

importandroid.graphics.Color;

importandroid.support.v7.app.AppCompatActivity;

importandroid.os.Bundle;

importandroid.view.View;

importandroid.widget.Button;

importandroid.widget.Toast;

publicclassMainActivityextendsAppCompatActivity{

privateButtonbutton;

@Override

protectedvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

button=(Button)this.findViewById(R.id.button);

finalint[]flag={0};

button.setOnClickListener(newButton.OnClickListener(){

@Override

publicvoidonClick(Viewv){

switch(flag[0]){

case0:

button.setBackgroundColor(Color.RED);

Toast.makeText(MainActivity.this,"当前背景色为红色",Toast.LENGTH_LONG).show();

flag[0]=1;

break;

case1:

button.setBackgroundColor(Color.GREEN);

Toast.makeText(MainActivity.this,"当前背景色为绿色",Toast.LENGTH_LONG).show();

flag[0]=2;

break;

case2:

button.setBackgroundColor(Color.BLUE);

Toast.makeText(MainActivity.this,"当前背景色为蓝色",Toast.LENGTH_LONG).show();

flag[0]=3;

break;

case3:

button.setBackgroundColor(Color.YELLOW);

Toast.makeText(MainActivity.this,"当前背景色为黄色",Toast.LENGTH_LONG).show();

flag[0]=0;

break;

}

}

});

}

}

 

运行效果:

4.

程序代码:

activity_main.xml

xmlversion="1.0"encoding="utf-8"?

>

android="

xmlns:

app="

xmlns:

tools="

android:

layout_width="match_parent"

android:

layout_height="match_parent"

tools:

context="firstandroidapp_by150104050020.myapplication.MainActivity">

xmlns:

android="

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

layout_gravity="center">

id="@+id/imagebutton"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

src="@drawable/button"

android:

onClick="showdialog0"/>

id="@+id/checkbox1"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="Chinese"/>

id="@+id/checkbox2"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="English"/>

id="@+id/button1"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="复选按钮确定"

android:

onClick="showdialog1"/>

id="@+id/radiogroup"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

orientation="horizontal">

id="@+id/radiobutton1"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="male"/>

id="@+id/radiobutton2"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="female"/>

id="@+id/button2"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="单选按钮确定"

android:

onClick="showdialog2"/>

MainActivity.java

packagefirstandroidapp_by150104050020.myapplication;

importandroid.content.DialogInterface;

importandroid.support.v7.app.AlertDialog;

importandroid.support.v7.app.AppCompatActivity;

importandroid.os.Bundle;

importandroid.view.View;

importandroid.widget.CheckBox;

importandroid.widget.RadioButton;

publicclassMainActivityextendsAppCompatActivity{

privateCheckBoxcheckbox1;

privateCheckBoxcheckbox2;

privateRadioButtonradiobutton1;

privateRadioButtonradiobutton2;

@Override

protectedvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

checkbox1=(CheckBox)this.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1