Banner(图片轮播)框架的使用

1.Gridle,Banner文件添加:
 compile 'com.youth.banner:banner:1.4.9'  //最新版本

compile 'com.github.bumptech.glide:glide:3.7.0'

compile 'jp.wasabeef:glide-transformations:1.0.6'

2.AndroidManifest.xml添加权限
<uses-permission android:name="android.permission.INTERNET" />//联网
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />//读取外置存储卡
3.添加布局文件
<com.youth.banner.Banner
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/banner"
    android:layout_width="match_parent"
    android:layout_height="150dp" />


5.实例化控件,添加数据集合
private void initView() {
    banner = (Banner) findViewById(R.id.banner);
    list_path = new ArrayList<>();
    list_title = new ArrayList<>();
    list_path.add("http://img.poco.cn/mypoco/myphoto/20071007/11/20071007114140_1251314291.jpg");
    list_path.add("http://img.poco.cn/mypoco/myphoto/20071007/11/20071007114140_1251314291.jpg");
    list_path.add("http://img.poco.cn/mypoco/myphoto/20071007/11/20071007114140_1251314291.jpg");
    list_path.add("http://img.poco.cn/mypoco/myphoto/20071007/11/20071007114140_1251314291.jpg");
    list_path.add("http://img.poco.cn/mypoco/myphoto/20071007/11/20071007114140_1251314291.jpg");
    list_path.add("http://img.poco.cn/mypoco/myphoto/20071007/11/20071007114140_1251314291.jpg");
    list_path.add("http://a3.att.hudong.com/72/76/01300000012339118647690465772.jpg");
    list_title.add("爱党");
    list_title.add("爱祖国");
    list_title.add("爱人民");
    list_title.add("爱社会");
    list_title.add("爱学习");
    list_title.add("爱劳动");
    list_title.add("爱妹子");
  

6.设置banner属性
 banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE);
    //设置图片加载器
    banner.setImageLoader(new MyLoader);
    //设置图片集合
    banner.setImages(list_path);
    //设置banner动画效果
    banner.setBannerAnimation(Transformer.DepthPage);
    //设置标题集合(当banner样式有显示title时)
    banner.setBannerTitles(list_title);
    //设置自动轮播,默认为true
    banner.isAutoPlay(true);
    //设置轮播时间
    banner.setDelayTime(1500);
    //设置指示器位置(当banner模式中有指示器时)
    banner.setIndicatorGravity(BannerConfig.CENTER);
    //banner设置方法全部调用完毕时最后调用
      banner.start();

7.自定义MyLoader类
private class MyLoader  extends ImageLoader {

    @Override

      public void displayImage(Context context, Object path, ImageView imageView) {

        Glide. with(context). load((String) path).into(imageView);       //传入路径,因为list为String格式,path为Object格式,所以强制类型转换.

    }

}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值