看代码吧,废话不多说了,关键方法是onPageScrollStateChanged()
public class GuideActivity extends BaseActivity implements ViewPager.OnPageChangeListener { private ViewPager viewPager; private CircleIndicator circleIndicator; private GuideAdapter adapter; private boolean misScrolled; private int position = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURENOTITLE); setContentView(R.layout.activityguide); viewPager = findView(R.id.container); viewPager.addOnPageChangeListener(this); circleIndicator = findView(R.id.indicator); adapter = new GuideAdapter(getSupportFragmentManager()); viewPager.setAdapter(adapter); circleIndicator.setViewPager(viewPager); } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { this.position = position; } @Override public void onPageScrollStateChanged(int state) { switch (state) { case ViewPager.SCROLLSTATEDRAGGING: misScrolled = false; break; case ViewPager.SCROLLSTATESETTLING: misScrolled = true; break; case ViewPager.SCROLLSTATE_IDLE: if (position == adapter.getCount() - 1 && !misScrolled) { startToMain(); } misScrolled = true; break; default: break; } } /** * 进入首页 */ private void startToMain() { MainActivity.actionViewUrlFromAsset(this, "Content/index.html"); finish(); } }
网上提供的另一种实现方法