1.依赖
compile 'com.youth.banner:banner:+'
2.图片加载
compile 'com.github.bumptech.glide:glide:3.6.1' 3.布局中调用依赖banner 4.MainActivitypublic class MainFragment extends Fragment { private String url = "http://120.27.23.105/ad/getAd"; private Banner banner; List<MainBean.DataBean> list = new ArrayList<>(); List<String> images = new ArrayList<>(); private Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); String s = (String) msg.obj; Gson gson = new Gson(); MainBean mainbean = gson.fromJson(s , MainBean.class); for (int i = 0; i < mainbean.getData().size(); i++) { images.add(mainbean.getData().get(i).getIcon()); } list = mainbean.getData(); banner.setImages(images); banner.start(); } }; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.mainfragment ,container ,false ); banner = (Banner) view.findViewById(R.id.banner); banner.setImageLoader(new GlideImageLoder()); banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR); banner.setIndicatorGravity(Banner.TEXT_ALIGNMENT_CENTER); banner.setDelayTime(2000); jiexi(); return view; } public class GlideImageLoder extends ImageLoader{ @Override public void displayImage(Context context, Object path, ImageView imageView) { Glide.with(context).load(path).into(imageView); } } private void jiexi() { OkHttp3Utils.doGet(url, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { String string = response.body().string(); Message message = new Message(); message.obj = string; handler.sendMessage(message); } }); } }