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);
}
}
网友评论