1.Banner介绍

现在的绝大数app都有banner界面,实现循环播放多个广告图片和手动滑动循环等功能。

2.使用环境配置(具体可见github开源项目)

(1)添加依赖

在build.gradle(app)文件内添加依赖

dependencies{
compile 'com.youth.banner:banner:1.4.10' //最新版本
   implementation 'com.github.bumptech.glide:glide:3.7.0'
}

(2)添加权限到你的 AndroidManifest.xml

<!-- if you want to load images from the internet -->
<uses-permission android:name="android.permission.INTERNET" /> <!-- if you want to load images from a file OR from the internet -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

(3)在布局文件中添加Banner,可以设置自定义属性

<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="高度自己设置" />

3.使用案例

(1)xml文件布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"> <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" /> </LinearLayout>

(2)java后台

<1>图片加载器

package com.example.administrator.test63advertisebanner;

import android.content.Context;
import android.widget.ImageView; import com.bumptech.glide.Glide;
import com.youth.banner.loader.ImageLoader; /**
* 图片加载器
*/
public class GlideImageLoader extends ImageLoader {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
//Glide 加载图片简单用法
Glide.with(context)
.load(path)
.into(imageView);
}
}

<2>MainActivity.java

package com.example.administrator.test63advertisebanner;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import com.youth.banner.Banner;
import com.youth.banner.BannerConfig; import java.util.ArrayList;
import java.util.List; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//资源文件
List<Integer> images=new ArrayList<>();
List<String> titleList=new ArrayList<>();
images.add(R.mipmap.a);
images.add(R.mipmap.b);
images.add(R.mipmap.c);
images.add(R.mipmap.d);
titleList.add("iphonexr牛逼");
titleList.add("手机王牌对王牌");
titleList.add("华为P30");
titleList.add("梁山伯与祝英台");
Banner banner = findViewById(R.id.banner);
//设置内置样式,共有六种可以点入方法内逐一体验使用。
banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE);
//设置图片加载器
banner.setImageLoader(new GlideImageLoader());
//设置图片集合
banner.setImages(images);
//设置轮播图的标题集合
banner.setBannerTitles(titleList);
//banner设置方法全部调用完毕时最后调用
banner.start();
}
}

4.效果图

029 Android 轮播图广告Banner开源框架使用的更多相关文章

  1. Android 轮播图Banner切换图片的效果

    Android XBanner使用详解 2018年03月14日 08:19:59 AND_Devil 阅读数:910   版权声明:本文为博主原创文章,未经博主允许不得转载. https://www. ...

  2. Android轮播图Banner的实现

    从慕课网上学了一门叫做“不一样的自定义实现轮播图效果”的课程,感觉实用性较强,而且循序渐进,很适合初学者.在此对该课程做一个小小的笔记. 实现轮播思路: 1.一般轮播图是由一组图片和底部轮播圆点组成, ...

  3. android ViewPager实现的轮播图广告自定义视图,网络获取图片和数据

    public class SlideShowAdView extends FrameLayout { //轮播图图片数量    private static int IMAGE_COUNT = 3;  ...

  4. android 轮播图

    轮播图是很常用的一个效果 核心功能已经实现 没有什么特殊需求 自己没事研究的 所以封装的不太好 一些地方还比较糙 为想要研究轮播图的同学提供个参考 目前测试图片为mipmap中的图片 没有写从网络加载 ...

  5. Android轮播图

    轮播图是很常用的一个效果 核心功能已经实现 没有什么特殊需求 自己没事研究的 所以封装的不太好 一些地方还比较糙 为想要研究轮播图的同学提供个参考目前测试图片为mipmap中的图片 没有写从网络加载图 ...

  6. android轮播图的实现原理

    1.轮播图的点:RadioGroup,根据网络请求的数据,解析得到的图片的个数,设置RadioGroup的RadioButton的个数. 2.轮播图的核心技术:用Gallery来存放图片,设置适配器. ...

  7. [android] 轮播图-滑动图片标题焦点

    谷歌提供的v4包,ViewPager 在布局文件中,先添加<android.support.v4.view.ViewPager/>控件,这个只是轮播的区域 在布局文件中,布置标题描述部分 ...

  8. ViewPager打造轮播图(Banner)\引导页(Guide)

    今年7月时,在Github发布了一个开源的Banner库,虽然Star不多,但还是有少部分人使用. Banner效果:  昨天,有使用此库的同学提出需求,想在引导页的时候用这个库并且最后一页有进入按钮 ...

  9. [android] 轮播图-无限循环

    实现无限循环 在getCount()方法中,返回一个很大的值,Integer.MAX_VALUE 在instantiateItem()方法中,获取当前View的索引时,进行取于操作,传递进来的int ...

随机推荐

  1. golang-切片

    切片练习 package main import "fmt" /*func main() { arr := [10]int {1, 2, 3, 4, 5, 6, 7, 8, 9, ...

  2. SpringMVC+Spring+Mybatis简单总结

    SpringMVC+Spring+Mybatis总结 第一部分:分析 web.xml中的配置 SSM框架的整合其实是Spring和SpringMVC的整合以及Spring和Mybatis进行整合. 当 ...

  3. 关于hexo与github使用过程中的问题与笔记

    快速阅读 如何用github 和hexo 创建一个blog 1.github中要新建一个与用户名同一样的仓库, 如:homehe.github.io - 必须是io后缀.一个帐户 只能建立一个 2. ...

  4. arcpy模块下的并行计算与大规模数据处理

    一个多星期的时间,忍着胃痛一直在做GIS 540: Spatial Programming的课程项目,导致其他方面均毫无进展,可惜可惜.在这个过程当中临时抱佛脚学习了很多Python相关的其他内容,并 ...

  5. 【转】python requests库添加自定义cookie的方法

    requests库是个很方便的爬虫,相关文档已经很详细了.不过我今天在爬网页时,有一个网站是在脚本中添加cookie的,但我向requests.cookies里添加cookie费了不少周折.尝试了多个 ...

  6. TLS整理(下):TLS如何保证安全

    明文 无法验证服务器的真实性 从而引出了TLS.本篇就来着重介绍下TLS. 说起TLS可能有些人还比较陌生,但如果说到SSL,那知道的人就更多了.TLS其实就是SSL发展而来,版本演进大体为SSL 2 ...

  7. (转载)RNA表观遗传学开创者何川

    何川,RNA表观遗传学开创者.早年毕业于中国科技大学,2000年获麻省理工学院博士学位,2000到2002年在哈佛大学做博士后研究,2002年至今执教芝加哥大学化学系, 是芝加哥大学生物物理动态研究所 ...

  8. 分库分表 or NewSQL数据库?终于看懂应该怎么选!【转】

    最近与同行科技交流,经常被问到分库分表与分布式数据库如何选择,网上也有很多关于中间件+传统关系数据库(分库分表)与NewSQL分布式数据库的文章,但有些观点与判断是我觉得是偏激的,脱离环境去评价方案好 ...

  9. python中修改列表元素的方法

    一.在for循环中直接更改列表中元素的值不会起作用: 如: l = list(range(10)[::2]) print (l) for n in l: n = 0 print (l) 运行结果: [ ...

  10. 从Windows转mac遇到的一些坑

    本屌由于运气,分了一台imac来办公,由于以前一直都在用windows,现在用Mac有很多不适应的地方.下面介绍一下Mac与Windows有明显区别的地方: mac与windows鼠标滑轮方向不同. ...