Android(安卓)实例-个人理财工具 之一 启动界面实现
16lz
2021-01-24
转 : http://hi.baidu.com/android%5Ffans/blog/item/299c0dfa37a60c116c22eb33.html 启动界面的主要功能就是显示一幅启动图像,后台进行系统初始化. 如果是第一次使用本程序,需要初始化本程序的sqlite数据库,建库,建Table,初始化账目数据. 如果不是第一次使用,就进入登记收支记录界面.
界面效果如图:
界面很简单,一个imageview 和一个textview 可是如何是2个view 垂直居中显示,我开始使用linearlayout就没法完成垂直和横向居中. 后来使用RelativeLayout 才搞定了横向居中. 界面的具体xml如下: main.xml- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout android:id="@+id/RelativeLayout01" xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_gravity="center_vertical|center_horizontal"
- android:layout_height="wrap_content"
- android:layout_width="wrap_content">
- <ImageView android:id="@+id/ImageView01"
- android:src="@drawable/logo3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- </ImageView>
- <TextView android:id="@+id/TextView01"
- android:text="@string/welcome"
- android:layout_below="@id/ImageView01"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- </TextView>
- </RelativeLayout>
- //给主线程发送消息更新imageview
- mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- super.handleMessage(msg);
- imageview.setAlpha(alpha);
- imageview.invalidate();
- }
- };
- new Thread(new Runnable() {
- public void run() {
- while (b < 2) {
- try {
- //延时2秒后,每50毫秒更新一次imageview
- if (b == 0) {
- Thread.sleep(2000);
- b = 1;
- } else {
- Thread.sleep(50);
- }
- updateApp();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }).start();
- public void updateApp() {
- alpha -= 5;//每次减少alpha 5
- if (alpha <= 0) {
- b = 2;
- Intent in = new Intent(this, com.cola.ui.Frm_Addbills.class);
- startActivity(in);//启动下个界面
- }
- mHandler.sendMessage(mHandler.obtainMessage());
- }
通过这段代码,我们能够理解android 里面如何对ui视图进行更新.
下篇文章我们来看看sqlite的使用.如何初始化程序.
关于handler,invalidate 的用法,
大家还可以参考这篇文章.http://www.blogjava.net/gooogle/archive/2008/03/05/184030.html
附ColaBox.java:- package com.cola.ui;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.Message;
- import android.util.Log;
- import android.view.KeyEvent;
- import android.widget.ImageView;
- import android.widget.TextView;
- public class ColaBox extends Activity {
- private Handler mHandler = new Handler();
- ImageView imageview;
- TextView textview;
- int alpha = 255;
- int b = 0;
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- imageview = (ImageView) this.findViewById(R.id.ImageView01);
- textview = (TextView) this.findViewById(R.id.TextView01);
- Log.v("ColaBox", "ColaBox start ...");
- imageview.setAlpha(alpha);
- new Thread(new Runnable() {
- public void run() {
- initApp(); //初始化程序
- while (b < 2) {
- try {
- if (b == 0) {
- Thread.sleep(2000);
- b = 1;
- } else {
- Thread.sleep(50);
- }
- updateApp();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }).start();
- mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- super.handleMessage(msg);
- imageview.setAlpha(alpha);
- imageview.invalidate();
- }
- };
- }
- public void updateApp() {
- alpha -= 5;
- if (alpha <= 0) {
- b = 2;
- Intent in = new Intent(this, com.cola.ui.Frm_Addbills.class);
- startActivity(in);
- }
- mHandler.sendMessage(mHandler.obtainMessage());
- }
- public void initApp(){
- }
- }
更多相关文章
- Android(安卓)应用初始化及窗体事件的分发
- 阿里路由框架ARouter简介
- Android中ScrollView布局初始化显示的时候使页面置顶
- Android(安卓)应用程序 生命周期
- 【Android】TV端项目开发挖坑总结
- 手把手教你给Eclipse配制Android
- Android(安卓)编译,打包、签程名详细教
- 让Python在Android系统上飞一会儿
- 基于.NET/C#开发跨平台Windows Phone 7、iPhone及Android应用程