首页 > 代码库 > android利用ViewPager做的介绍软件功能demo
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(); } }
android利用ViewPager做的介绍软件功能demo
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。