package com.ming.chiye.yishanghorse.Adapter;
import android.content.Context;
import android.graphics.Color;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.lidroid.xutils.BitmapUtils;
import com.ming.chiye.yishanghorse.Bean.TeacherInitDataBean;
import com.ming.chiye.yishanghorse.Utils.MyLog;
import java.util.ArrayList;
import java.util.List;
public class TeachrtCarouselAdapter extends PagerAdapter {
List<TeacherInitDataBean.ContainerBean> ContainerBeans;
private final List<ImageView> imageViews;
public TeachrtCarouselAdapter(List<TeacherInitDataBean.ContainerBean> ContainerBeans, Context context) {
super();
this.ContainerBeans = ContainerBeans;
imageViews = new ArrayList<>();
BitmapUtils bitmapUtils = new BitmapUtils(context);
for (int i = 0; i < ContainerBeans.size(); i++) {
ImageView imageView = new ImageView(context);
imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
String url = ContainerBeans.get(i).getImgurl();
bitmapUtils.display(imageView, url);
imageViews.add(i + 1, imageView);
if (i == 0) {
ImageView imageView1 = new ImageView(context);
bitmapUtils.display(imageView1, url);
imageViews.add(ContainerBeans.size() + 1, imageView1);
}
if (i == ContainerBeans.size() - 1){
ImageView imageView2 = new ImageView(context);
bitmapUtils.display(imageView2, url);
imageViews.add(0, imageView2);
}
}
ImageView lastimageview = new ImageView(context);
lastimageview.setImageDrawable(imageViews.get(0).getDrawable());
imageViews.add(lastimageview);
}
@Override
public int getCount() {
return imageViews.size();
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
return view == o;//
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
container.addView(imageViews.get(position));//将image添加到容器中显示
return imageViews.get(position);//返回当前下标要显示的imageview
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView(imageViews.get(position));//销毁的item
}
}