效果图:
启动页:
package com.bfec.educationplatform.models.navigation.ui.activity; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import com.bfec.BaseFramework.libraries.common.util.storage.SharedPrefUtil; import com.bfec.educationplatform.R; import java.lang.ref.WeakReference; /** * 启动页 */ public class StartPageAty extends Activity { private static final int WHAT_HOME = 1000; private static final int WHAT_GUIDE = 1001; private static final int DELAY_TIME = 2000; private StartPageHandler handler = new StartPageHandler(this); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.start_page); // Init final String KEY_IS_FIRST = "isFirst"; SharedPrefUtil spUtil = SharedPrefUtil.getInstance(this, "config", MODE_PRIVATE); if (spUtil.getBool(KEY_IS_FIRST, true)) { handler.sendEmptyMessageDelayed(WHAT_GUIDE, DELAY_TIME); spUtil.putBool(KEY_IS_FIRST, false).commit(); } else handler.sendEmptyMessageDelayed(WHAT_HOME, DELAY_TIME); } private void goDestination(Class cls) { startActivity(new Intent(this, cls)); finish(); } private static class StartPageHandler extends Handler { private WeakReference<StartPageAty> mAty; public StartPageHandler(StartPageAty aty) { mAty = new WeakReference<>(aty); } @Override public void handleMessage(Message msg) { StartPageAty aty = mAty.get(); if (aty == null) return; switch (msg.what) { case WHAT_GUIDE: // 引导页 aty.goDestination(GuideAty.class); break; case WHAT_HOME: // 首页 aty.goDestination(HomePageAty.class); } } } }
引导页:
package com.bfec.educationplatform.models.navigation.ui.activity; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.ImageView.ScaleType; import android.widget.LinearLayout; import com.bfec.educationplatform.R; import com.bfec.educationplatform.models.navigation.ui.adapter.ViewPagerAdapter; import java.util.ArrayList; /** * 引导页 */ public class GuideAty extends Activity { // 图片资源ID private static final int[] IMG_ID = {R.drawable.u1_state0, R.drawable.u1_state1, R.drawable.u1_state2}; // ViewPager private ViewPager viewPager; private ArrayList<View> views = new ArrayList<>(); // 开始按钮 private Button btnStart; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.start_guide); // ViewPager LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(-1, -1); for (int id : IMG_ID) { ImageView imgView = new ImageView(this); imgView.setLayoutParams(params); imgView.setScaleType(ScaleType.FIT_XY); imgView.setImageResource(id); views.add(imgView); } ViewPagerAdapter vpAdapter = new ViewPagerAdapter(views); viewPager = (ViewPager) findViewById(R.id.viewpager); viewPager.setAdapter(vpAdapter); viewPager.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { setCurPage(position); if (position == IMG_ID.length - 1) btnStart.setVisibility(View.VISIBLE); else btnStart.setVisibility(View.GONE); } @Override public void onPageScrollStateChanged(int state) { } }); // 开始按钮 btnStart = (Button) findViewById(R.id.startbtn); btnStart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(GuideAty.this, HomePageAty.class)); finish(); } }); } private void setCurPage(int position) { viewPager.setCurrentItem(position); } }