码迷,mamicode.com
首页 > 移动开发 > 详细

android利用ViewPager做的介绍软件功能demo

时间:2014-11-23 11:50:03      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:android   软件   viewpager   

<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

标签:android   软件   viewpager   

原文地址:http://blog.csdn.net/u014600432/article/details/41408845

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!