android首页Splash页面简单实现

/**
 * 启动界面
 */
public class SplashActivity extends BaseActivity {
   RelativeLayout view;
   public static IWXAPI WX_api;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      view = (RelativeLayout) View.inflate(this, R.layout.layout_splash, null);
      setContentView(view);
      try {
         new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
               checkUpdate();
               init();
            }
         }, 2000);
      } catch (Exception e) {

      }
     
   }

   private void init() {
	//可以在这里初始化一些东西

   }

   /**
    * 检查更新
    */
   private void checkUpdate() {
      new UpdateManager(this).checkUpdate(new UpdateCallBack() {
         @Override
         public void checkUpdateComplete(boolean update) {
            if (!update)
               jumpOrShowGuidance();
         }

         @Override
         public void cancel() {
            jumpOrShowGuidance();
         }
         
         @Override
         public void close() {
            finish();
         }
      });
   }

   /**
    * 跳转还是显示引导界面   主要是这个方法
    */
   private void jumpOrShowGuidance() {
	//取出之前存储的应用版本号,默认是0
      int guiVersion = PreferenceUitl.getInstance(mContext).getInt(PreferenceColums.hadShowGuidance, 0);	//获取当前应用版本号
      int versionCode = Integer.parseInt(YktApplication.get().versionCode);
	//对比当前应用版本号和之前存储的版本号
      if (versionCode > guiVersion) {
         // 只有当前应用版本大于保存的引导展示版本,就显示引导页面
         PreferenceUitl.getInstance(mContext).saveInt(PreferenceColums.hadShowGuidance, versionCode);
         GuidanceView guidanceView = new GuidanceView(mContext);
         view.addView(guidanceView);
      } else {
         ActivityMain.start(mContext);
         finish();
      }
   }
}
 
/**  
GuidanceView 的代码
*/
/**
 * 引导页面

 */
public class GuidanceView extends RelativeLayout {

   private ViewPager vp_guidance;

   private List<View> viewList;

   public GuidanceView(Context context) {
      super(context);
      initGuidanceView();
      init();
   }

   private void init() {
      vp_guidance = new ViewPager(getContext());
      vp_guidance.setAdapter(pagerAdapter);
      addView(vp_guidance);
   }

   /**
    * 初始化引导的UI
    */
   private void initGuidanceView() {
      viewList = new ArrayList<View>();
      LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

      ImageView iv_01 = new ImageView(getContext());
      iv_01.setBackgroundResource(R.drawable.guide1);
      iv_01.setLayoutParams(params);

      ImageView iv_02 = new ImageView(getContext());
      iv_02.setBackgroundResource(R.drawable.guide2);
      iv_02.setLayoutParams(params);

      ImageView iv_03 = new ImageView(getContext());
      iv_03.setBackgroundResource(R.drawable.guide3);
      iv_03.setLayoutParams(params);

      View view_04 = LayoutInflater.from(getContext()).inflate(R.layout.custom_guidance, null);
      view_04.findViewById(R.id.view_guidance_btn_enter).setOnClickListener(onClickListener);

      viewList.add(iv_01);
      viewList.add(iv_02);
      viewList.add(iv_03);
      viewList.add(view_04);

   }

   private OnClickListener onClickListener = new OnClickListener() {

      @Override
      public void onClick(View v) {
         // //第四个引导页面,点击进入跳转至首页
         ActivityMain.start((Activity) getContext());
         ((Activity) getContext()).finish();
      }
   };

   /**
    * 引导页面的数据适配器
    */
   private PagerAdapter pagerAdapter = new PagerAdapter() {

      @Override
      public boolean isViewFromObject(View arg0, Object arg1) {

         return arg0 == arg1;
      }

      @Override
      public int getCount() {

         return viewList.size();
      }

      @Override
      public void destroyItem(ViewGroup container, int position, Object object) {
         container.removeView(viewList.get(position));

      }

      @Override
      public int getItemPosition(Object object) {

         return super.getItemPosition(object);
      }

      @Override
      public Object instantiateItem(ViewGroup container, int position) {
         container.addView(viewList.get(position));
         return viewList.get(position);
      }

   };
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值