FlyBanner轮播图 和 XBanner轮播图

FlyBanner轮播图
1、添加依赖

compile 'com.recker.flybanner:flybanner:1.3' 

2、XML布局


3、MainActivity

public class MainActivity extends AppCompatActivity {
	    private FlyBanner banner;
    	private String[] mImagesUrl = {
            "http://attach.bbs.miui.com/forum/201303/16/173716jzszx8vbbb0z9o4k.jpg",
            "http://pic.58pic.com/58pic/13/16/42/18F58PIChTy_1024.jpg",
            "http://pic28.photophoto.cn/20130929/0034034819144555_b.jpg", };
            
	     @Override
   		 public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v =  inflater.inflate(R.layout.fragment22, container, false);
        initNetBanner(v);
        return v;
   	 }
	   
	   private void initNetBanner(View v) {
        	banner = v.findViewById(R.id.banner);
        	List imgesUrl = new ArrayList<>();
        	for (int i = 0; i < mImagesUrl.length; i++) {
            	imgesUrl.add(mImagesUrl[i]);
       		}
        	banner.setImagesUrl(imgesUrl);
  	 	 }
    }

XBanner轮播图
1、依赖

implementation 'com.github.xiaohaibin:XBanner:1.6.1'   【当前app的build.grade】
maven { url 'https://jitpack.io' }   【在项目的build.grade】

2、XML



3 MainActivity

	private List list = new ArrayList<>();
	private ArrayList mImgesUrl = new ArrayList<>();  //存放图片路径的集合

    if (success instanceof LunboBean) {    //轮播
            LunboBean lunboBean = (LunboBean) success;
            list.addAll(lunboBean.getResult());
            for (int i = 0; i < list.size(); i++) {
                mImgesUrl.add(list.get(i).getImageUrl());
            }
            if (!mImgesUrl.isEmpty()) {
                banner.setData(mImgesUrl, null);
                banner.loadImage(new XBanner.XBannerAdapter() {
                    @Override
                    public void loadBanner(XBanner banner, Object model, View view, int position) {
                        Glide.with(getActivity()).load(mImgesUrl.get(position)).into((ImageView) view);
                    }
                });
                banner.setPageChangeDuration(1000);
                banner.setPageTransformer(Transformer.Default);
            }
        } 

你可能感兴趣的:(FlyBanner轮播图 和 XBanner轮播图)