实验内容:
- 实验实现3-4个Activity之间的跳转,包括注册页面、登录页面、好友列表页面等。实验必须使用两种以上的布局方式完成Acitivity的设计。
- 其中用户注册界面中需要出现8种以上的Android基本控件,并在Activity文件中对业务逻辑进行规范:如密码必须匹配,性别必须选择、年龄必须在一个合理范围内等等,当用户填写内容不正确时给出有效的提示。此界面可以做到国际化效果。可参照老师课堂上的案例。
实现好友列表界面,相应ListView中OnItemClick的点击事件。
实验步骤:
首先先新建一个项目。
1.登录页面:
(1)新建一个LoginActivity.kt文件,并在res目录的layout文件夹中创建activity_login.xml文件。有关登录页面的实现效果都在这两个文件中体现。
(2)先将布局方式改成RelativeLayout布局,如果想在页面中添加背景,可以添加android:background这个属性。
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".LoginActivity">
</RelativeLayout>
(3)添加文字和样式:设置TextView和EditText的id、宽度(layout_width)、高度(layout_height)、字体大小(textSize)、文本(text)、文字的对齐方式(gravity)、控件的对齐方式(layout_gravity)等。
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".LoginActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/big_login"
android:textSize="40dp"
android:text="登录"
android:gravity="center"
android:layout_gravity="center_vertical"
android:layout_margin="30dp" />
<!-- 手机号-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Layoutstyle">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text_name"
android:text="手机号码:"
android:textSize="22dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/username"
android:layout_marginLeft="0dp"
android:hint="请输入手机号"
android:textColor="@color/black"
android:gravity="center_vertical"
android:textSize="25dp"/>
</LinearLayout>
<!-- 密码-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Layoutstyle">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text_pwd"
android:text="密\u3000\u3000码:"
android:textSize="22dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/pwd"
android:hint="请输入密码"
android:textColor="@color/black"
android:gravity="center_vertical"
android:inputType="textPassword"
android:textSize="22dp"
android:layout