源码简介
最近一直在研究关于分页的,***发现还是goole官方的好用些,今天就顺便写了一两个model来和大家分享一下,上传的那个viewpage,因为自己都搞不太懂,被人骂了,写的不全面,其实,本来就不全面,我一般都只是传点model上来的,项目肯定是不会这么轻易地上传上来的,都是项目上遇到什么问题解决之后就上传上来和大家分享了,可以左右滑动。
源码运行截图
源码片段:
- private void init(){
- options = new DisplayImageOptions.Builder()
- .showImageOnLoading(R.drawable.image_loading)
- .showImageForEmptyUri(R.drawable.image_empty)
- .showImageOnFail(R.drawable.image_error)
- .cacheInMemory(true)
- .cacheOnDisk(true)
- .considerExifParams(true)
- .bitmapConfig(Bitmap.Config.RGB_565)
- .build();
- //载入图片资源ID
- myPageTestModels=new ArrayList<mypagetestmodel>();
- mImageViews=new ImageView[23];
- MyPageTestModel mTestModel;
- for (int i = 0; i < 23; i++) {
- mTestModel=new MyPageTestModel();
- mTestModel.setId(i);
- mTestModel.setName("name"+i);
- mTestModel.setUrl("http://www.amsoft.cn/content/templates/amsoft/images/rand/"+i+".jpg");
- myPageTestModels.add(mTestModel);
- }
- //将点点加入到ViewGroup中
- tips = new ImageView[myPageTestModels.size()];
- for(int i=0; i<tips.length; i++){="" imageview="" imageview(this);="" imageview.setlayoutparams(new="" layoutparams(10,10));="" tips[i]="imageView;" if(i="=" 0){="" tips[i].setbackgroundresource(r.drawable.page_indicator_focused);="" }else{="" tips[i].setbackgroundresource(r.drawable.page_indicator_unfocused);="" }="" linearlayout.layoutparams="" layoutparams="new" linearlayout.layoutparams(new="" viewgroup.layoutparams(layoutparams.wrap_content,="" layoutparams.wrap_content));="" layoutparams.leftmargin="5;" layoutparams.rightmargin="5;" group.addview(imageview,="" layoutparams);="" views="new" arraylist<view="">();
- //创建每一页需要显示的图文信息
- for(int i=0;i<mypagetestmodels.size();i++){ view="" mpageview="LayoutInflater.from(MyPageActivity2.this).inflate(R.layout.page_gridview_item," null);="" imageview="" mpageimageview="(ImageView)" mpageview.findviewbyid(r.id.itemsicon);="" textview="" mtextview="(TextView)mPageView." findviewbyid(r.id.mypagetext);="" imageloader.displayimage(mypagetestmodels.get(i).geturl(),="" mpageimageview);="" mpageimageview.setimageresource(r.drawable.ic_launcher);="" mtextview.settext(mypagetestmodels.get(i).getname());="" views.add(mpageview);="" }="" 设置adapter="" viewpager.setadapter(new="" mypageadapter(mypageactivity2.this,="" views));="" 设置监听,主要是设置点点的背景="" viewpager.setonpagechangelistener(this);="" 设置viewpager的默认项,="" 设置为长度的100倍,这样子开始就能往左滑动="" viewpager.setcurrentitem((mypagetestmodels.size())="" *="" 100);="" }<="" pre="">
- </mypagetestmodels.size();i++){></tips.length;></mypagetestmodel>
源码链接:http://down.51cto.com/data/1983048