1.当滑动到最后一页时显示立即进入按钮,其实也是判断viewpager的事件。当滑动到最后一个时显示就行。其它时候都隐藏
//实现自己的PagerAdapter方法
MyPagerAdapter pagerAdapter = new MyPagerAdapter();
vp.setAdapter(pagerAdapter);
//对滑动进行监听
vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
if (position == 2) {//判断当滑动到第三页时进行操作
btn_welcome.setVisibility(View.VISIBLE);//设置控件为可看见
btn_welcome.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(WelcomeActivity.this, DrawerLayoutActivity.class));//窗体跳转
finish();//结束本窗体
}
});
} else {
btn_welcome.setVisibility(View.GONE);//否则不可见
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
class MyPagerAdapter extends PagerAdapter {
@Override
public int getCount() {//返回页面的数量
return imgs.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {//实例化页面
ImageView imageView = new ImageView(WelcomeActivity.this);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setImageResource(imgs[position]);
container.addView(imageView);//添加页面
return imageView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);//移除页面
}
}
}
2.闪屏功能的实现
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_welcome);
handleWelcome();
}
/**
* 处理欢迎页面
*/
private void handleWelcome() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//打开主页并关闭欢迎页面
Intent intent = new Intent(SplashActivity.this, WelcomeActivity.class);
startActivity(intent);
SplashActivity.this.finish();
}
},1500);
}
}