android程序启动画面之Splash总结[转]
方法一:
很多应用都会有一个启动界面。欢迎画面慢慢隐现,然后慢慢消隐。实现这种效果的方法有两种(暂时只发现两种)
1、使用两个Activity,程序启动时候load第一张Activity,然后由tick触发N秒钟后startActivity另外一张Activity。
2、使用一个Activity,可以用到View.gone() 这个方法。把Acitivity的某些元素移除。
1、两个Activity:
首先是AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sunshine.splash"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Splash"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="Main">
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
然后是JAVA代码:
package net.hlovey.splash;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class Splash extends Activity {
private final int SPLASH_DISPLAY_LENGHT = 3000; //延迟三秒
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
Intent mainIntent = new Intent(Splash.this,Main.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, SPLASH_DISPLAY_LENGHT);
}
}
当然可以再Splash中加入动画效果。(我觉得先要布局好AndroidManifest.xml。因为那才是工程的索引文件。首先在那要有一个统筹!而不是先写java code。然后逐步往xml中增加 ,这说明对整个项目没有一个统筹的设计)
方法二:
androidmanifest.xml就不多说了。先看布局代码:
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>
<LinearLayout android:id=”@+id/splashscreen” android:orientation=”vertical”
android:layout_width=”fill_parent” android:layout_height=”fill_parent”>
<ImageView android:layout_width=”wrap_content”
android:layout_height=”wrap_content” android:src=”@drawable/splash”
android:layout_gravity=”center”
android:layout_marginTop=”130px”/>
<TextView
android:id=”@+id/info”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:gravity=”center”
android:paddingTop=”10px”
android:text=”This is a splash!!”/>
</LinearLayout>
<WebView android:id=”@+id/browser”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent” android:layout_weight=”1″/>
</LinearLayout>
有一个id为splashscreen 的linearlayout,是程序启动时显现的部分。id为browser是程序的主界面显示部分。
package net.hlovey.s;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class WebGameActivity extends Activity {
private WebView webView;
private Handler mHandler = new Handler();
private static final String TAG = "WebGameActivity";
//菜单
private static final int MENU_RELOAD = Menu.FIRST;
private static final int MENU_HELP = Menu.FIRST + 1;
private static final int MENU_ABOUT = Menu.FIRST + 2;
private static final int MENU_CLOSE = Menu.FIRST + 3;
private int staus = 0;
private static final int STOPSPLASH = 0;
//time in milliseconds
private static final long SPLASHTIME = 1000;
private LinearLayout splash;
private TextView tv;
private Animation myAnimation_Alpha;
private Animation animatinoGone ;
private Handler splashHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case STOPSPLASH:
if( staus == 1 ){
splash.startAnimation(animatinoGone);
splash.setVisibility(View.GONE);
break;
}
sendEmptyMessageDelayed(STOPSPLASH, SPLASHTIME);
}
super.handleMessage(msg);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_PROGRESS); //去标题栏
setContentView(R.layout.main);
animatinoGone = AnimationUtils.loadAnimation(this,R.anim.alpha_gone); //动画效果
myAnimation_Alpha = AnimationUtils.loadAnimation(this,R.anim.alpha_action); //动画效果
splash = (LinearLayout) findViewById(R.id.splashscreen);
tv = (TextView) findViewById(R.id.info);
tv.setText("正在建立数据连接");
splash.startAnimation(myAnimation_Alpha);
Message msg = new Message();
msg.what = STOPSPLASH;
splashHandler.sendMessageDelayed(msg, SPLASHTIME);
}
------------------------------------------------------------------------------------------
每个Android应用启动之后都会出现一个Splash启动界面,显示产品的LOGO、公司的LOGO或者开发者信息。如果应用程序启动时间比较长,那么启动界面就是一个很好的东西,可以让用户耐心等待这段枯燥的时间。
- 制作Splash界面
突出产品LOGO,产品名称,产品主要特色;
注明产品的版本信息;
注明公司信息或者开发者信息;
背景图片,亦可以用背景颜色代替; - 除了等待还能做点什么
大多数的Splash界面都是会等待一定时间,然后切换到下一个界面;
其实,在这段时间里,可以对系统状况进行检测,比如网络是否通,电源是否充足;
或者,预先加载相关数据;
为了能让启动界面展现时间固定,需要计算执行以上预处理任务所花费的时间,那么:启动界面SLEEP的时间=固定时间-预处理任务时间 - 源码示例(以Wordpress的Android客户端为例)
AndroidMenifest.xml
<activity android:icon="@drawable/app_icon"
android:screenOrientation="portrait"
android:name=".splashScreen"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
splashScreen.java
package org.wordpress.android;import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.os.Handler;
import android.view.WindowManager;
import android.widget.TextView;publicclass splashScreen extends Activity {
/**
* Called when the activity is first created.
*/@Override
publicvoid onCreate(Bundle icicle) {
super.onCreate(icicle);
getWindow().setFormat(PixelFormat.RGBA_8888);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);setContentView(R.layout.splashscreen);
//Display the current version number
PackageManager pm = getPackageManager();
try {
PackageInfo pi = pm.getPackageInfo("org.wordpress.android", 0);
TextView versionNumber = (TextView) findViewById(R.id.versionNumber);
versionNumber.setText("Version "+ pi.versionName);
} catch (NameNotFoundException e) {
e.printStackTrace();
}new Handler().postDelayed(new Runnable() {
publicvoid run() {
/* Create an Intent that will start the Main WordPress Activity. */
Intent mainIntent =new Intent(splashScreen.this, wpAndroid.class);
splashScreen.this.startActivity(mainIntent);
splashScreen.this.finish();
}
}, 2900); //2900 for release}
}
splashscreen.xml
<!--
android:gravity是对元素本身说的,元素本身的文本显示在什么地方靠着换个属性设置,不过不设置默认是在左侧的。
android:layout_gravity是相对与它的父元素说的,说明元素显示在父元素的什么位置
-->
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center|center"
android:background="@drawable/home_gradient"
android:orientation="vertical">
<!--
android:scaleType是控制图片如何resized/moved来匹对ImageView的size
CENTER_INSIDE / centerInside 将图片的内容完整居中显示,通过按比例缩小或原来的size使得图片长/宽等于或小于View的长/宽
-->
<ImageView android:layout_marginTop="-60dip"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:scaleType="centerInside"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/wordpress_logo"
android:src="@drawable/wordpress_home">
</ImageView>
<!--
android:typeface 字体风格
-->
<TextView android:text="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:typeface="serif"
android:shadowDx="0"
android:shadowDy="2"
android:shadowRadius="1"
android:shadowColor="#FFFFFF"
android:textColor="#444444"
android:textSize="20dip"
android:id="@+id/versionNumber"
android:gravity="bottom">
</TextView>
</LinearLayout>
android程序启动画面之Splash总结[转]的更多相关文章
- Android -- 程序启动画面 Splash
很多应用都会有一个启动界面.欢迎画面慢慢隐现,然后慢慢消隐. 我的方式是使用两个Activity,程序启动时候load第一张Activity,然后由tick触发N秒钟后startActivity另外一 ...
- Delphi开发 Android 程序启动画面简单完美解决方案
原文在这里 还是这个方法好用,简单!加上牧马人做的自动生成工具,更是简单. 以下为原文,向波哥敬礼! 前面和音儿一起研究 Android 下启动画面的问题,虽然问题得到了解决,但是,总是感觉太麻烦,主 ...
- Android程序启动加载动画实现
package com.example.bmob_test.ui;//程序启动动画,图片颜色由浅到深,方法一 import com.example.bmob_test.LogActivity; imp ...
- Delphi Android程序启动过程
Delphi的Android程序是原生的程序,也就是NativeActivity.那么就需要先看一下NativeActivity的原理, 在AndroidManifest.xml文件里面指定入口act ...
- Android程序启动过程深入解析
当按下Android设备电源键时究竟发生了什么? Android的启动过程是怎么样的? 什么是Linux内核? 桌面系统linux内核与Android系统linux内核有什么区别? 什么是引导装载程序 ...
- 比较windows phone程序启动和android程序启动原理
windows phone 程序是如何启动的了,他和android程序有什么区别,我们重点从native code 层面来分析 在windows phone 程序启动的时候是: 在XAML中使用应用程 ...
- Android程序启动程序与页面的跳转
package login; import com.example.login.R; import android.app.Activity; import android.content.Inten ...
- Android WelcomeActivity 启动画更换网络图片
1.运行效果 第一张是本地的启动图,第二张是网络启动图 2.用到的第三方jar包 Android-Universal-Image-Loader-master 不熟的请看 Andro ...
- Android App 启动页(Splash)黑/白闪屏现象产生原因与解决办法(转)
转载: Android App 启动页(Splash)黑/白闪屏现象产生原因与解决办法 首先感谢博主分享,本文作为学习记录 惊鸿一瞥 微信的启动页,相信大家都不陌生. 不知道大家有没有发现一个现象 ...
随机推荐
- crt 糟心的配置
每次要下载安装crt就要捣鼓半天,各种注册机下来各种问题,顺手记录下刚打通的一个 1.crt 下载 网上看了一遍博客: SecureCRT 7.3.4破解版(含注册机), 下载下来后里面其实是不含注册 ...
- MongoDB(二)
通过程序来操作数据库: //链接字符串 string connectionString = "mongodb://192.168.1.107"; //数据库名 string dat ...
- vb listview 的常用操作
常用操作:获取当前行数和列数: MsgBox "行数:" & ListView1.ListItems.Count & "列数:" & L ...
- [转]iOS UIAppearance使用详解
在iOS 5以前,自定义原生控件的外观并没有原生支持,因此开发人员感觉很麻烦.开发人员经常面临的问题是修改一个控件所有实例的外观.解决这个问题的正确方法是重写一遍控件.但由于这么做非常费时,一些开发人 ...
- CodeForces - 61E Enemy is weak
Description The Romans have attacked again. This time they are much more than the Persians but Shapu ...
- ceph 参数说明<转>
//path/to/socket指向某个osd的admin socket文件#> ceph --admin-daemon {path/to/socket} config show | grep ...
- DataReader转泛型
实体类的字段类型要和数据库一致,不然可能会出现错误. /// <summary> /// DataReader转泛型 /// </summary> /// <typepa ...
- .net 文件下载
/** 输入参数* _Request: Page.Request 对象* _Response: Page.Response 对象* _fileName: 下载文件名* _fullPath: 带文件名下 ...
- python文件目录遍历保存成xml文件代码
Linux服务器有CentOS.Fedora等,都预先安装了Python,版本从2.4到2.5不等,而Windows类型的服务器也多数安装了Python,因此只要在本机写好一个脚本,上传到对应机器,在 ...
- 表A中有两个表示时间的字段A,B;如果B的值大于A的值,则把B的值更新为A的值
sql语句:表A中有两个表示时间的字段A,B:如果B的值大于A的值,则把B的值更新为A的值 update 表名 set B=A where B>A