zoukankan      html  css  js  c++  java
  • 手机安全卫士开发系列(2)——splash界面

    一、Android中的MVC

    (1)activity主要用来页面的展示

    (2)engine包:获取数据和展示数据(包含数据适配器)

    (3)domain包:存放数据实体

    第一种包结构组织关系:


    第二种包结构:

     利用程序的业务逻辑进行代码划分,比如QQ, qq有登陆模块,聊天模块,群组模块,qq空间模块

    com.tencent.login

    com.tencent.im

    com.tencent.group

    com.tencent.zoom

    二、建立工程和包

    splash主要用于闪屏的显示(包括产品logo显示,数据库初始化,获取服务器最新信息是否有新版本更新,)

    市场上不少应用会在不同时间显示不同logo,这是怎么做的呢?是事先偷偷的将logo就下载好了,到了特定的某一天就会加载到该界面。

    我建立的工程如下:


    要注意在mainfest文件里面的路径配置:package=" "  android:name=" "

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.mobiesafe"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="17" />
    
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name=".ui.SplashActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    
    </manifest>
    


    现在创建布局文件splash.xml

    <?xml version="1.0" encoding="utf-8"?>
    <!-- 线性布局 -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/logo2"
        android:gravity="center_horizontal"
        android:orientation="vertical" 
        android:id="@+id/ll_splash_main"
        >
    	<!-- 显示版本号 -->
        <TextView
            android:id="@+id/tv_splash_version"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="280dip"
            android:text="版本号"
            android:textColor="#FF01b6f8"
            android:textSize="20sp" />
    	<!-- 下载进度条 -->
        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dip" />
    
    </LinearLayout>


    SplashActivity

    package com.meritit.mobiesafe.ui;
    
    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.content.pm.PackageInfo;
    import android.content.pm.PackageManager;
    import android.os.Bundle;
    import android.view.Window;
    import android.view.WindowManager;
    import android.view.animation.AlphaAnimation;
    import android.widget.LinearLayout;
    import android.widget.TextView;
    
    import com.example.mobiesafe.R;
    
    public class SplashActivity extends Activity {
    	private static final String TAG = "SplashActivity";
    	private TextView tv_splash_version;
    	private LinearLayout ll_splash_main;
    	private ProgressDialog pd ;
    	private String versiontext;
    
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		// 取消标题栏
    		requestWindowFeature(Window.FEATURE_NO_TITLE);
    		setContentView(R.layout.splash);
    		ll_splash_main = (LinearLayout) this.findViewById(R.id.ll_splash_main);
    		tv_splash_version = (TextView) this
    				.findViewById(R.id.tv_splash_version);
    		versiontext = getVersion();
    		tv_splash_version.setText(versiontext);
    		AlphaAnimation aa = new AlphaAnimation(0.0f, 1.0f);
    		aa.setDuration(2000);
    		ll_splash_main.startAnimation(aa);
    
    		// 完成窗体的全屏显示 // 取消掉状态栏
    		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    				WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
    	}
    
    	/**
    	 * 获取当前应用程序的版本号
    	 * 
    	 * @return
    	 */
    	private String getVersion() {
    		try {
    			//包管理服务
    			PackageManager manager = getPackageManager();
    			//第一个参数为包名
    			PackageInfo info = manager.getPackageInfo(getPackageName(), 0);
    			return info.versionName;
    		} catch (Exception e) {
    
    			e.printStackTrace();
    			return "版本号未知";
    		}
    	}
    	
    }
    


    运行结果



    源代码下载:http://download.csdn.net/detail/lxq_xsyu/5928701



  • 相关阅读:
    mongodb修改和删除操作
    mongodb常用查询语句
    ejs常用功能函数
    Rails + React +antd + Redux环境搭建
    nodejs安装和卸载
    Git 建立仓库及常用命令速查表
    使用MVC5+Entity Framework6的Code First模式创建数据库并实现增删改查功能
    gem devise配置
    Ubuntu16.04安装postgresql9.4及pgadmin3图形管理界面
    Rails Migration Data Model栏位修改及数据类型介绍
  • 原文地址:https://www.cnblogs.com/pangblog/p/3257982.html
Copyright © 2011-2022 走看看