美文网首页
PhotoView+ViewPager

PhotoView+ViewPager

作者: 最黑暗的自己 | 来源:发表于2018-03-22 11:44 被阅读28次
          for (int i = 0; i < img.length; i++) {
                ImageView imageView=new ImageView(this);
                imageView.setImageResource(img[i]);
                PhotoViewAttacher photoViewAttacher = new PhotoViewAttacher(imageView);  //使图片实现可以放大缩小的功能PhotoVIew
                views.add(imageView);
            }
            vp = findViewById(R.id.vp);
            PageAdapter pageAdapter = new PageAdapter(views);
            vp.setAdapter(pageAdapter);
    
    //Adapter
    public class PageAdapter extends PagerAdapter {
        List<View> views;
        public PageAdapter(List<View> views) {
            this.views=views;
        }
    
        @Override
        public int getCount() {
            return views.size();
        }
    
        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view==object;
        }
    
        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            View view = views.get(position);
            container.addView(view);
            return view;
        }
    
        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            View view = views.get(position);
            container.removeView(view);
        }
    }
    

    相关文章

      网友评论

          本文标题:PhotoView+ViewPager

          本文链接:https://www.haomeiwen.com/subject/wufaqftx.html