Banner的使用

来源:互联网 发布:php java .net的区别 编辑:程序博客网 时间:2024/06/05 16:36
 private Banner banner;    private List<String>mlist=new ArrayList<>();    @Nullable    @Override    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {      View view=inflater.inflate(R.layout.homefragment,container,false);        banner = (Banner) view.findViewById(R.id.homebanner);        mlist.add("http://f2.kkmh.com/image/170703/x5ikta5vz.webp-w320");        mlist.add("http://f2.kkmh.com/image/170703/xpdwlbmf9.webp-w640");        mlist.add("http://f2.kkmh.com/image/170724/w6mvk3nj2.webp-w640");        mlist.add(" http://f2.kkmh.com/image/170707/o6rfyyext.webp-w640");       initData();        return view;    }    private void initData() {        //设置图片加载器        banner.setImageLoader(new GlideImageLoader());        //设置图片集合        banner.setImages(mlist);        //设置banner动画效果        banner.setBannerAnimation(Transformer.DepthPage);        //设置自动轮播,默认为true        banner.isAutoPlay(true);        //设置轮播时间        banner.setDelayTime(1500);        //设置指示器位置(当banner模式中有指示器时)        banner.setIndicatorGravity(BannerConfig.CENTER);        //banner设置方法全部调用完毕时最后调用        banner.start();    }    public class GlideImageLoader extends ImageLoader {        @Override        public void displayImage(Context context, Object path, ImageView imageView) {            /**             注意:             1.图片加载器由自己选择,这里不限制,只是提供几种使用方法             2.返回的图片路径为Object类型,由于不能确定你到底使用的那种图片加载器,             传输的到的是什么格式,那么这种就使用Object接收和返回,你只需要强转成你传输的类型就行,             切记不要胡乱强转!             */            //Glide 加载图片简单用法            Glide.with(context).load(path).into(imageView);        }    }

}

compile 'com.android.support:recyclerview-v7:25.3.1'compile 'com.github.bumptech.glide:glide:3.8.0'compile 'com.google.code.gson:gson:2.8.1'compile 'com.squareup.okhttp3:okhttp:3.8.1'compile 'org.xutils:xutils:3.5.0'compile 'com.youth.banner:banner:1.4.9'