zoukankan      html  css  js  c++  java
  • Android 应用页面延缓载入

    1.新建一个线程,使用handle的延缓运行线程

    new Handler().postDelayed(new Runnable() {
                       // 为了减少代码使用匿名Handler创建一个延时的调用
        public void run() {
            Intent i = new Intent(SplashActivity.this, MainActivity.class );
            startActivity(i);
            finish();
            overridePendingTransition(R.anim. in_1, R.anim.out_1);
            }
        }, 2000 );//延缓2秒

    2.通过handler延缓发送广播

    public class SplashActivity extends Activity {
    
           private Handler handler;
           private final int NOTIFY_CLOSE_ACTIVITY = 1;
           private int SPLASH_DISPLAY_LENGHT = 2000; // 延迟两秒
    
           @Override
           protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_splash);
    
                initialize();
                handler.removeMessages(NOTIFY_CLOSE_ACTIVITY);
                handler.sendEmptyMessageDelayed(NOTIFY_CLOSE_ACTIVITY, SPLASH_DISPLAY_LENGHT);
           
          }
    
           private void initialize() {
                 handler = new Handler() {
                       @Override
                       public void handleMessage(Message msg) {
                             // TODO Auto-generated method stub
                             super.handleMessage(msg);
                             switch (msg.what ) {
                             case NOTIFY_CLOSE_ACTIVITY :
                                  goMain();
                                   break;
                             default:
                                   break;
                             }
                      }
                };
          }
          
           private void goMain(){
                Intent intent = new Intent(SplashActivity.this, MainActivity.class );
                 this.startActivity(intent);
                 this.finish();
          };
    }

    3.使用动画

    public class SplashActivity extends Activity {
    
           @Override
           protected void onCreate(Bundle savedInstanceState) {
                 super.onCreate(savedInstanceState);
                
                View view = View. inflate(this, R.layout. activity_splash, null);
                setContentView(view);
                
                 //动画效果参数直接定义
            Animation animation = new AlphaAnimation(0.1f, 1.0f);
            animation.setDuration(5000);
            view.setAnimation(animation);
           
            animation.setAnimationListener( new AnimationListener() {
               
                @Override
                public void onAnimationStart(Animation animation) {
                }
               
                @Override
                public void onAnimationRepeat(Animation animation) {
                }
               
                @Override
                public void onAnimationEnd(Animation animation) {
                    goMain();
                }
            });
           
          }
          
           private void goMain(){
                Intent intent = new Intent(SplashActivity.this, MainActivity.class );
                 this.startActivity(intent);
                 this.finish();
          };
    }

    4.使用CountDownTimer http://www.cnblogs.com/over140/archive/2011/12/20/2294220.html

    定时执行在一段时候后停止的倒计时,在倒计时执行过程中会在固定间隔时间得到通知(译者:触发onTick方法)

            new CountDownTimer(3000 ,1000){
    
                @Override
                public void onTick(long millisUntilFinished) {
                    // TODO Auto-generated method stub
                    System.out.println("-------onFinish---------");
                }
    
                @Override
                public void onFinish() {
                    // TODO Auto-generated method stub
                    System.out.println("-------onFinish---------");
                }
                
            }.start();
  • 相关阅读:
    通用权限管理设计 之 数据库结构设计
    jQuery LigerUI 插件介绍及使用之ligerDateEditor
    jQuery LigerUI 插件介绍及使用之ligerTree
    jQuery LigerUI V1.01(包括API和全部源码) 发布
    jQuery liger ui ligerGrid 打造通用的分页排序查询表格(提供下载)
    jQuery LigerUI V1.1.5 (包括API和全部源码) 发布
    jQuery LigerUI 使用教程表格篇(1)
    jQuery LigerUI V1.0(包括API和全部源码) 发布
    jQuery LigerUI V1.1.0 (包括API和全部源码) 发布
    nginx keepalived
  • 原文地址:https://www.cnblogs.com/sishuiliuyun/p/3305137.html
Copyright © 2011-2022 走看看