android利用ViewPager做的介绍软件功能demo
<pre name="code" class="java">/** * 介绍该软件的功能 * @author yqq * */ public class WhatNewActivity extends Activity { private ViewPager mViewPager; private ImageView mPage0; private ImageView mPage1; private ImageView mPage2; private ImageView mPage3; private SharedPreferences mPreferences; private int currIndex = 0; public WhatNewActivity() { // TODO Auto-generated constructor stub } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_what_one); mViewPager = (ViewPager)findViewById(R.id.whatsnew_viewpager); mViewPager.setOnPageChangeListener(new MyOnPageChangeListener()); mPage0 = (ImageView)findViewById(R.id.page0); mPage1 = (ImageView)findViewById(R.id.page1); mPage2 = (ImageView)findViewById(R.id.page2); mPage3 = (ImageView)findViewById(R.id.page3); //将要分页显示的View装入数组中 LayoutInflater mLi = LayoutInflater.from(this); View view2 = mLi.inflate(R.layout.activity_what2, null); view2.setAlpha(50); View view3 = mLi.inflate(R.layout.activity_what3, null); view3.setAlpha(50); View view5 = mLi.inflate(R.layout.activity_what5, null); view5.setAlpha(50); View view6 = mLi.inflate(R.layout.activity_goto_main, null); view6.setAlpha(50); //每个页面的view数据 final ArrayList<View> views = new ArrayList<View>(); views.add(view2); views.add(view3); views.add(view5); views.add(view6); //填充ViewPager的数据适配器 PagerAdapter mPagerAdapter = new PagerAdapter() { @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == arg1; } @Override public int getCount() { return views.size(); } @Override public void destroyItem(View container, int position, Object object) { ((ViewPager)container).removeView(views.get(position)); } @Override public Object instantiateItem(View container, int position) { ((ViewPager)container).addView(views.get(position)); return views.get(position); } }; mViewPager.setAdapter(mPagerAdapter); } public class MyOnPageChangeListener implements OnPageChangeListener { @Override public void onPageSelected(int arg0) { switch (arg0) { case 0: mPage0.setImageDrawable(getResources().getDrawable(R.drawable.page_now)); mPage1.setImageDrawable(getResources().getDrawable(R.drawable.page)); break; case 1: mPage1.setImageDrawable(getResources().getDrawable(R.drawable.page_now)); mPage0.setImageDrawable(getResources().getDrawable(R.drawable.page)); mPage2.setImageDrawable(getResources().getDrawable(R.drawable.page)); break; case 2: mPage2.setImageDrawable(getResources().getDrawable(R.drawable.page_now)); mPage1.setImageDrawable(getResources().getDrawable(R.drawable.page)); mPage3.setImageDrawable(getResources().getDrawable(R.drawable.page)); break; case 3: mPage3.setImageDrawable(getResources().getDrawable(R.drawable.page_now)); mPage2.setImageDrawable(getResources().getDrawable(R.drawable.page)); break; } currIndex = arg0; } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int arg0) { } } public void startbutton(View v) { mPreferences=getSharedPreferences("Config",MODE_PRIVATE); Editor editor=mPreferences.edit(); editor.putBoolean("isFirst", false); editor.commit(); Intent intent = new Intent(); intent.setClass(WhatNewActivity.this,WhatDoorActivity.class); startActivity(intent); overridePendingTransition(R.anim.tran_next_in, R.anim.tran_next_out); this.finish(); } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。