方法一:
很多应用都会有一个启动界面。欢迎画面慢慢隐现,然后慢慢消隐。实现这种效果的方法有两种(暂时只发现两种)
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);
}
方法一:
很多应用都会有一个启动界面。欢迎画面慢慢隐现,然后慢慢消隐。实现这种效果的方法有两种(暂时只发现两种)
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 Screen在应用程序是很常用的,往往在启动界面中显示产品Logo、公司Logo或者开发者信息,如果应用程序启动时间比较长,那么启动界面就是一个很好的东西,可以让用户耐心等待这段枯燥的时间。...
很多Android程序在启动时首先会显示一个封面(Splash窗口),过一会才进入主界面。Splash窗口通常是全屏的,一般会显示与程序相关的logo、公司标识等.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分...
一、Splash界面的作用 用来展现产品的Logo 应用程序初始化的操作 检查应用程序的版本 检查当前应用程序是否合法注册 二、界面的xml定义 写一个布局背景设置为产品的logo图片,再添加一个textview显示版本号。 <...
每个Android应用程序启动之后都会出现一个Splash启动界面,显示产品LOGO、公司LOGO或者开发者信息。如果应用程序启动时间比较长,那么启动界面就是一个很好的东西,可以让用户耐心等待这段枯燥的时间,提高用户体验...
什么是SplashSplash也就是应用程序启动之前先启动一个画面,上面简单的介绍应用程序的厂商,厂商的LOGO,名称和版本等信息,多为一张图片,显示几秒钟后会自动消息,然后显示出应用程序的主体页面。在PC上,很常见...
在应用程序中经常用到启动画面,会启动一个后台线程为主程序的运行准备资源。 Android要实现启动画面可以这样做: 这是splash.xml布局文件的代码: 代码如下:<LinearLayout xmlns:android=”...
很多Android程序在启动时首先会显示一个封面(Splash窗口),过一会才进入主界面。Splash窗口通常是全屏的,一般会显示与程序相关的logo、公司标识等。实现这个功能的方法很多,这里将给出一个比较简单且灵活的实现...
在Android上启动画面 目录 介绍 在某些时候,您可能会发现自己需要为Android应用实现启动屏幕。 这样做的原因包括匹配适用于iOS的现有设计,在启动时执行必要的背景工作,或仅出于视觉吸引力。 应该注意的是,您的...
该源码是Splash引导进入界面效果,该源码由源码天堂android源码整理提供,很多Android程序在启动时首先会显示一个封面(Splash窗口),过一会才进入主界面。Splash窗口通常是全屏的,一般会显示与程序相关的logo、公司...
打开您的应用程序后,原生应用程序会在很短的时间内加载Flutter。 默认情况下,在此期间,本机应用程序显示白色的初始屏幕。...1.设置启动画面自定义以下设置,并将其添加到项目的pubspec.yaml文件中,或放
适用于Android和iOS的动画启动画面。 它基于来自RN的。 这使用Image而不是MaskedView在两个平台上都可以工作。 SplashAnimated示例应用程序。 特征 自定义背景色。 自定义背景图片。 自定义徽标。 自定义徽标...
实现Splash的简化版本,每次启动程序时演示一个类似于微信的使用界面帮助用户学习如何使用软件。
我已经开始使用iOS 8 的移动网络应用程序图标和启动画面尺寸。 然而,我还没有验证所有这些——这是一个巨大的痛苦。 我希望这个项目支持所有平台,而不仅仅是 iOS。 我只是没有要测试的 Android。这个怎么运作在...
Android的APP应用中最常用的APP启动引导页,常见的4种引导项目方式:splash,viewpage,viewflipper,scrollview.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
CommonRemoveBlackPage解决android冷启动黑画面的问题的一个综合解决方案,附带状态栏导航栏控制的demo工程。同时实现了微信splash页面只启动一次的效果,splash页面还可以继续去做初始化框架和各种第三方库的操作。...
Android演示-启动画面 材料设计启动画面的小样本 本示例尝试实现“物料设计启动/飞溅”屏幕。 它没有各种大小的所有可绘制对象,因此有点作弊,它仅实现xxxhdpi,但它应该提供一个基本的应用程序,用于在冷启动加载...
现在,iOS 13和Android Q支持黑暗模式,我们也希望应用程序的启动画面也变黑。 此示例演示如何创建一个启动屏幕,当启用“暗模式”时该屏幕为黑色,而当禁用“暗模式”时该屏幕仍为浅。 我最近在和上为我的应用程序...
天气应用 ... 应用程序首先使用运行 2300 秒的 SplashScreen 活动加载启动画面,然后将自身重定向到主活动。 这是一个练习应用程序,我主要是在其中学习将天气集成到原生 Andorid 应用程序中。