Android实验报告_界面设计

西安邮电大学

(计算机学院)

课内实验报告

实验名称Andorid界面设计

专业名称:计算机科学与技术

班级:1405班

学生姓名:高宏伟

学号(8位):04141152

指导教师:孟伟君

实验日期:2017 年 4 月7 日

第一次实验Android界面设计

一. 实验目的及实验环境

1. 实验目的

1)掌握常用组件在布局文件中的设置

2)掌握在Java程序中获取组件值

3)掌握对组件的验证

4)掌握基本组件常用的监听器,和时间处理

5)掌握将组件值提交到下一个Activity活动的方法

6)了解四种布局管理器的区别和各自特有的属性

7)掌握四种布局管理器的应用场合和用法

8)灵活使用四种布局管理器的嵌套实现各种复杂布局

9)掌握复用XML布局文件的方法

10)掌握代码控制UI界面的方法

2.实验环境

系统开发平Android Studio 2.3.1

系统开发平台:Android

运行平台:Windows XP及以上

运行环境:https://www.360docs.net/doc/ce16070886.html, Framework SDK 23.2

二. 实验教材、组织方式、实验内容

1.实验教材:Andorid开发与应用

2.组织方式:个人独立完成

2.实验内容:

运用基本组件和布局管理器的相关知识完成一个界面设计。

完成教材p242,p247上的内容,两个内容合并完成制作一个Android应用UI的开发(图片不限),要求当点击不同的组件时要有对应的界面显示和操作。

三.方案设计

1.设计UI界面

主布局采用线性布局LinearLayout,垂直排列

主布局中添加有用户名文本框和输入框,密码文本框和输入框性别文本框和复选框,联系电话文本框和复选框

部门文本框和列表框

爱好文本框和一个线性布局

主布局最后有一个确定按钮

四.运行结果

五.总结

1.实验过程中遇到的问题及解决办法;

实验的时候写好的程序不能正常的输出到安卓模拟器,咨询同学之后,对模拟器进行了重新建立,问题解决。

2.对设计及调试过程的心得体会。

通过这次实验掌握了常用组件在布局文件中的设置方法以及在Java程序中获取组件值,掌握了对组件的验证,监听器的使用和事件处理方法,掌握了将组件值提交到下一个Activity活动的方法。

六.附录:源代码

主布局文件:

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:padding="10dp" >

android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="用户名:" />

android:id="@+id/username"

android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10"

android:inputType="textPersonName" >

android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp"

android:text="密码:" />

android:id="@+id/userpassword"

android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10"

android:inputType="textPassword" >

android:id="@+id/remember"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="记住密码" />

android:id="@+id/autologin"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="自动登录" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="性别" />

android:id="@+id/choosenet"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal" >

android:id="@+id/boy"

android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="男" />

android:id="@+id/girl"

android:layout_width="wrap_content"

android:text="女" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="联系电话" />

android:layout_width="fill_parent"

android:layout_height="wrap_content" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="部门" />

android:id = "@+id/dept"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:entries = "@array/dept" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="爱好" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal" >

android:layout_height="wrap_content" android:text = "书籍" />

android:layout_width="wrap_content"

android:layout_height="wrap_content" android:text = "运动" />

android:layout_width="wrap_content"

android:layout_height="wrap_content" android:text = "音乐" />

android:layout_width="wrap_content"

android:layout_height="wrap_content" android:text = "电影" />

android:id="@+id/login"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="确定" />

主Activity文件:

package com.example.autologin;

import android.app.Activity;

import android.content.Intent;

import android.content.SharedPreferences;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.CheckBox;

import android.widget.EditText;

import android.widget.Toast;

public class LoginActivity extends Activity {

private EditText username;

private EditText userpassword;

private CheckBox remember;

private CheckBox autologin;

private Button login;

private SharedPreferences sp;

private String userNameValue,passwordValue;

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(https://www.360docs.net/doc/ce16070886.html,yout.login);

// 初始化用户名、密码、记住密码、自动登录、登录按钮

username = (EditText) findViewById(https://www.360docs.net/doc/ce16070886.html,ername);

userpassword = (EditText) findViewById(https://www.360docs.net/doc/ce16070886.html,erpassword);

remember = (CheckBox) findViewById(R.id.remember);

autologin = (CheckBox) findViewById(R.id.autologin);

login = (Button) findViewById(R.id.login);

sp = getSharedPreferences("userInfo", 0);

String name=sp.getString("USER_NAME", "");

String pass =sp.getString("PASSWORD", "");

boolean choseRemember =sp.getBoolean("remember", false); boolean choseAutoLogin =sp.getBoolean("autologin", false);

// Toast.makeText(this, name, Toast.LENGTH_SHORT).show(); if(choseRemember){

username.setText(name);

userpassword.setText(pass);

remember.setChecked(true);

}

if(choseAutoLogin){

autologin.setChecked(true);

}

login.setOnClickListener(new OnClickListener() {

// 默认可登录帐号ghw123456,密码123456

public void onClick(View arg0) {

userNameValue = username.getText().toString();

passwordValue = userpassword.getText().toString();

SharedPreferences.Editor editor =sp.edit();

// TODO Auto-generated method stub

if (userNameValue.equals("ghw123456")

&& passwordValue.equals("123456")) {

Toast.makeText(LoginActivity.this, "登录成功",

Toast.LENGTH_SHORT).show();

//保存用户名和密码

editor.putString("USER_NAME", userNameValue);

editor.putString("PASSWORD", passwordValue);

if(remember.isChecked()){

editor.putBoolean("remember", true);

}else{

editor.putBoolean("remember", false);

}

if(autologin.isChecked()){

editor.putBoolean("autologin", true);

}else{

editor.putBoolean("autologin", false);

}

https://www.360docs.net/doc/ce16070886.html,mit();

Intent intent =new Intent(LoginActivity.this,SuccessActivity.class);

startActivity(intent);

} else {

Toast.makeText(LoginActivity.this, "用户名或密码错误,请重新登录!",

Toast.LENGTH_SHORT).show();

}

}

});

}

}

相关文档
最新文档