效果图:

  


首先,  在drawable下放入XML splash_animation.xml


建立 splash_view.xml

<?xml version="1.0" encoding="utf-8"?>            



建立 SplashDemoActivity

public class SplashDemoActivity extends Activity {public final static String tag = SplashDemoActivity.class.getSimpleName();public final static int SPLASH_DURATION = 2000;private ImageView imageView = null;private AnimationDrawable animationDrawable = null;private boolean isPressBack = false;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.splash_view);imageView = (ImageView) findViewById(R.id.wait_image_view);imageView.setBackgroundResource(R.drawable.splash_animation);animationDrawable = (AnimationDrawable) imageView.getBackground(); }protected void onResume() {super.onResume();// 开始动画 -- 用在此处,不能保证每次动画都行运行,//because the AnimationDrawable is not yet fully attached to the window//startSplashAnimation(SPLASH_DURATION);}@Overridepublic void onWindowFocusChanged(boolean hasFocus) {if (hasFocus) {// 开始动画startSplashAnimation(SPLASH_DURATION);}}/** * Description: Run the splash screen for given time limit* @param limit */protected void startSplashAnimation(final int limit) {Thread splashThread = new Thread() {@Overridepublic void run() {try {//Thread.currentThread().sleep(50);////不能在onCreate中立即执行,because the AnimationDrawable is not yet fully attached to the windowanimationDrawable.start();int waited = 0;while (waited < limit) {sleep(100);waited += 100;}} catch (Exception e) {Log.w(tag, e.getMessage().toString());finish();} finally {if (!isPressBack) {//解决在SPLASH_DURATION期间内, 用户点击back键,应用会在再次自动重启forwardActivity();}}}};splashThread.start();}@Overrideprotected void onDestroy() {super.onDestroy();imageView = null;animationDrawable = null;}public boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0){isPressBack = true;finish();return true;}return false;}private void forwardActivity(){Intent intent = new Intent(SplashDemoActivity.this, MainActivity.class);intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);startActivity(intent);finish();//SplashDemoActivity.this.overridePendingTransition(R.anim.translucent_enter, R.anim.translucent_exit);//SplashDemoActivity.this.overridePendingTransition(R.anim.fade, R.anim.hold);//这个overridePendingTransition效果经常不好使, 不知为何???overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);}}

zoom_enter.xml

<?xml version="1.0" encoding="utf-8"?>    

zoom_exit.xml

<?xml version="1.0" encoding="utf-8"?>        





更多相关文章

  1. android 动画
  2. Android实现Zaker的加载对话框
  3. 【Android】【动画】自定义插值器Interpolator
  4. android对话框弹出方式动画
  5. android 动画框架
  6. Android旋转动画
  7. DialogFragment设置自定义动画
  8. Android(安卓)Recyclerview设置条目属性动画
  9. android 滑动动画效果

随机推荐

  1. Android(安卓)Build (1) -- Source Code
  2. Android启动Activity的两种方式
  3. Android(安卓)Studio自定义模板 写页面竟
  4. Android自定义动画专题一
  5. Android(安卓)进程间通信的几种实现方式
  6. Android中的进程和线程
  7. Android(安卓)RotateAnimation详解
  8. ADT转AndroidStudio建议
  9. Android学习记录1
  10. Android(安卓)IPC入门——AIDL