例程实现的界面如下
设计这个界面应该比较的简单,只需要一些基本的布局知识就可以了,这里主要是TextView中的跑马灯的效果,用到的属性是:android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever",下面就直接介绍布局文件layout:
<pre name="code" class="html"><LinearLayout 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:orientation="vertical" >
<!-- 通过 android:text实现TextView显示的文本 -->
<!-- 通过android:ellipsize实现跑马灯效果 -->
<!-- 通过 android:textSize实现控制字体大小 -->
<!-- 通过android:marqueeRepeatLimit设置跑马灯效果循环无限次 -->
<TextView
android:id="@+id/firstView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="欢 迎 您 登 录 成 绩 查 询 系 统,祝 您好 运 !!!!!"
android:textSize="20sp" />
<LinearLayout
android:id="@+id/linear1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<!-- 通过android:textColor设置字体颜色 -->
<!-- 通过android:textStyle设置字形 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="学 号:"
android:textColor="#ff0000"
android:textSize="20sp"
android:textStyle="bold" />
<!-- 通过android:hint设置输入提示信息 -->
<!-- 通过android:inputType设置数字输入格式 -->
<EditText
android:id="@+id/numberET"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="请输入学号"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:id="@+id/linear2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="姓 名:"
android:textColor="#ff0000"
android:textSize="20sp"
android:textStyle="bold" />
<EditText
android:id="@+id/nameET"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="请输入姓名" />
</LinearLayout>
<LinearLayout
android:id="@+id/linear3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密 码:"
android:textColor="#ff0000"
android:textSize="20sp"
android:textStyle="bold" />
<!-- 通过password属性设置输入文本以点显示 -->
<EditText
android:id="@+id/passwordET"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="请输入密码"
android:password="true" />
</LinearLayout>
<Button
android:id="@+id/loginBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="登 录"
android:textSize="20sp" />
</LinearLayout>
mainactivity中的功能代码如下:
<pre name="code" class="java">package com.toby.chap3_2_1;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView firstView;
private EditText numberET, nameET, passwordET;
private Button loginBtn;
private String number, name, password;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firstView = (TextView) findViewById(R.id.firstView);// 根据ID获取到TextView对象
numberET = (EditText) findViewById(R.id.numberET);// 根据ID获取到EditText对象
nameET = (EditText) findViewById(R.id.nameET);
passwordET = (EditText) findViewById(R.id.passwordET);
loginBtn = (Button) findViewById(R.id.loginBtn);// 根据ID获取到Button对象
loginBtn.setOnClickListener(new OnClickListener() {// 对Button实现点击事件监听
@Override
public void onClick(View v) {// 设置点击Button后要执行的操作
number = numberET.getText().toString();// 获取文本框输入的内容
name = nameET.getText().toString();
password = passwordET.getText().toString();
if (number.equals("001") && name.equals("001")
&& password.equals("001")) {
firstView.setText(name + "同学您已经登录成绩查询系统!");
} else {
firstView.setText("您的输入有误,请重新输入!!!");
}
}
});
}
}