当前位置:操作系统 > 安卓/Android >>

Splash的几种运用

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>

 

 

摘自 gongzibai的专栏

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,