创建一个Handler.postDelayed,延迟2秒或者更多,之后切换到
另一ACTIVITY界面.
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
// TODO Auto-generated method stub
Intent it = new Intent(Splash.this, Youban1Activity.class);
startActivity(it);
finish();
}
}, 2000);
}
--------------加入动画
Animation mAnimation = AnimationUtils.loadAnimation(this,
R.anim.scaleanimation);
则先播放动画后切换到另一AVTIVITY界面
--------------------------
package youbanwang.co.cc;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
public class Splash extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
// TODO Auto-generated method stub
Intent it = new Intent(Splash.this, Youban1Activity.class);
startActivity(it);
finish();
}
}, 2000);
}
}
------------------自动展示图片SPLASH
package tangshi.co.cc;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;
public class Splash extends Activity {
private ImageView mImageView;
private Handler mHandler;
private final int SPLASH1 = 0;
private final int SPLASH2 = 1;
private final int SPLASH3 = 2;
private final int TURNTOLOGIN = 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
mImageView = (ImageView) findViewById(R.id.imageView1);
mImageView.setImageResource(R.drawable.icon1);
mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch (msg.what) {
case SPLASH1:
mImageView.setImageResource(R.drawable.icon1);
break;
case SPLASH2:
mImageView.setImageResource(R.drawable.icon2);
break;
case SPLASH3:
mImageView.setImageResource(R.drawable.icon3);
break;
case TURNTOLOGIN:
mImageView.setImageResource(R.drawable.icon4);
break;
default:
break;
}
};
};
new Thread() {
public void run() {
try {
sleep(1000);
mHandler.sendEmptyMessageDelayed(SPLASH1, 0);
sleep(1000);
mHandler.sendEmptyMessageDelayed(SPLASH2, 0);
Thread.sleep(1000);
mHandler.sendEmptyMessageDelayed(SPLASH3, 0);
sleep(2000);
mHandler.sendEmptyMessageDelayed(TURNTOLOGIN, 0);
} catch (Exception e) {
// TODO: handle exception
} finally {
Intent intent = new Intent(Splash.this,
HahamxActivity.class);
startActivity(intent);
finish();
}
};
}.start();
}
}
---------Splash animation
package gongzibai.co.cc;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
public class Splash extends Activity {
private ImageView mImageView;
private TextView mTextView;
Animation animation;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash1);
mImageView = (ImageView) findViewById(R.id.imageView1);
mTextView=(TextView)findViewById(R.id.textView1);
Animation mAnimation = AnimationUtils.loadAnimation(this,
R.anim.scaleanimation);
mImageView.startAnimation(mAnimation);
mTextView.startAnimation(mAnimation);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Intent it = new Intent(Splash.this, RandomActivity.class);
startActivity(it);
finish();
}
}, 2000);
}
}
---------anim
<?xml version="1.0" encoding="UTF-8"?>
<set android:shareInterpolator="false" xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="3000"
></alpha>
</set>