设为首页 加入收藏

TOP

Android程序启动画面之Splash总结(一)
2014-11-24 11:17:52 来源: 作者: 【 】 浏览:2
Tags:Android 程序 启动 画面 Splash 总结

方法一:


很多应用都会有一个启动界面。欢迎画面慢慢隐现,然后慢慢消隐。实现这种效果的方法有两种(暂时只发现两种)
1、使用两个Activity,程序启动时候load第一张Activity,然后由tick触发N秒钟后startActivity另外一张Activity。
2、使用一个Activity,可以用到View.gone() 这个方法。把Acitivity的某些元素移除。


< xml version="1.0" encoding="utf-8" >
package="com.sunshine.splash"
android:versionCode="1"
android:versionName="1.0">

android:label="@string/app_name">










然后是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″ >
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>
android:layout_width=”fill_parent” android:layout_height=”fill_parent”>
android:layout_height=”wrap_content” android:src=”@drawable/splash”
android:layout_gravity=”center”
android:layout_marginTop=”130px”/>
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!!”/>

android:layout_width=”fill_parent”
android:layout_height=”fill_parent” android:layout_weight=”1″/>


有一个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;

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇利用ffmpeg框架扩展Android平台解.. 下一篇Android编程 - 列表控件使用

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Redis on AWS:Elast (2025-12-27 04:19:30)
·在 Spring Boot 项目 (2025-12-27 04:19:27)
·使用华为开发者空间 (2025-12-27 04:19:24)
·Getting Started wit (2025-12-27 03:49:24)
·Ubuntu 上最好用的中 (2025-12-27 03:49:20)