android起始页面与导航页面

每一次打开QQ或者支付宝都会有一个相同的起始页面,而第一次打开app还会有一个导航页面。

起始页面用一个ImageView 就可以了,而导航页面则需要一个v4包下面的ViewPage。

起始页面代码如下:

public class StartActivity extends BaseActivity {
	private ImageView ivSplash;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.startactivity);
		ivSplash = (ImageView) findViewById(R.id.ivSplash);
		AlphaAnimation anim = new AlphaAnimation(0f, 1f);
		anim.setDuration(2000);
		anim.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation arg0) {

			}

			@Override
			public void onAnimationRepeat(Animation arg0) {

			}

			@Override
			public void onAnimationEnd(Animation arg0) {
				skip();
			}
		});
		ivSplash.startAnimation(anim);
	}

	public void skip() {
		Intent intent = new Intent();
		intent.setClass(this, GuideActivity.class);
		startActivity(intent);
		finish();
	}
}

导航页面代码如下:

public class GuideActivity extends BaseActivity {

	private android.support.v4.view.ViewPager vpContent;
	private Button btnSkip;
	private int[] datas;

	private void bindViews() {
		vpContent = (android.support.v4.view.ViewPager) findViewById(R.id.vpContent);
		btnSkip = (Button) findViewById(R.id.btnSkip);
		btnSkip.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				skip();
			}
		});
	}

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.guideactivity);
		bindViews();
		datas = new int[] { R.drawable.launch_1, R.drawable.launch_2,
				R.drawable.launch_3, R.drawable.launch_4 };
		vpContent.setAdapter(new MyPagerAdapter());
		vpContent.setOnPageChangeListener(new OnPageChangeListener() {
			public void onPageSelected(int position) {
				if (position == 3) {
					btnSkip.setVisibility(View.VISIBLE);
				} else {
					btnSkip.setVisibility(View.INVISIBLE);
				}
			}

			public void onPageScrolled(int arg0, float arg1, int arg2) {

			}

			public void onPageScrollStateChanged(int arg0) {

			}
		});
	}

	public void skip() {
		System.out.println("进入skip()");
		Intent intent = new Intent();
		intent.setClass(this, LoginActiviy.class);
		startActivity(intent);
		finish();
	}

	class MyPagerAdapter extends PagerAdapter {

		@Override
		public int getCount() {
			return datas.length;
		}

		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			return arg0 == arg1;
		}

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

		@Override
		public Object instantiateItem(ViewGroup container, int position) {
			int i = datas[position];
			ImageView imageView = new ImageView(GuideActivity.this);
			imageView.setBackgroundResource(i);
			container.addView(imageView);
			return imageView;
		}

	}
}

android起始页面与导航页面_第1张图片

你可能感兴趣的:(Android)