zoukankan      html  css  js  c++  java
  • ViewPager滑动页面的实现方法

    package com.lixu.pagerview;
    
    import java.util.ArrayList;
    
    import android.app.Activity;
    import android.content.Context;
    import android.os.Bundle;
    import android.support.v4.view.PagerAdapter;
    import android.support.v4.view.ViewPager;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ImageView;
    
    public class MainActivity extends Activity {
        ViewPager mViewPager;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mViewPager = (ViewPager) findViewById(R.id.vp);
            PagerAdapter mPagerAdapter = new myAdapter(this);
            mViewPager.setAdapter(mPagerAdapter);//设置适配器
        }
    
        public class myAdapter extends PagerAdapter {
            private ArrayList<ImageView> views;
            private Context context;
    
            @Override
            public int getCount() {
                return views.size();
            }
    
            public myAdapter(Context context) {
                views = new ArrayList<ImageView>();
                this.context = context;
                int[] image = new int[] { R.drawable.a1, R.drawable.a10, R.drawable.a2, R.drawable.aa8, R.drawable.aa9,//设置图片id
                        R.drawable.f14 };
                for (int i = 0; i < 6; i++) {
                    ImageView mImageView = new ImageView(context);
                    mImageView.setImageResource(image[i]);
                    views.add(mImageView);
    
                }
    
            }
    
            @Override
            public View instantiateItem(ViewGroup container, int position) {
                container.addView(views.get(position));
                return views.get(position);
            }
    
            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                container.removeView(views.get(position));
            }
    
            @Override
            public boolean isViewFromObject(View arg0, Object arg1) {
                return arg0 == arg1;
            }
    
        }
    }
  • 相关阅读:
    c# 命令行下编译c#文件 // c# file类读写文件
    C#读取Xml
    System.IO.Path
    System.IO.Path 操作
    关于C#操作INI文件的总结
    C# 文件的一些基本操作(转)//用C#读写ini配置文件
    使用匿名类型做为ComboBox的DataSource
    C# Path 有关于文件路径等问题类(转)
    自考新教材--p60_5_2
    自考新教材--p60_5_1
  • 原文地址:https://www.cnblogs.com/labixiaoxin/p/4932649.html
Copyright © 2011-2022 走看看