Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/bingoogolapple/BGABanner-Android

引导界面滑动导航 + 大于等于1页时无限轮播 + 各种切换动画轮播效果
https://github.com/bingoogolapple/BGABanner-Android

androidx banner splash

Last synced: about 23 hours ago
JSON representation

引导界面滑动导航 + 大于等于1页时无限轮播 + 各种切换动画轮播效果

Lists

README

        

:running:BGABanner-Android:running:
============

## 目录

* [功能介绍](#功能介绍)
* [效果图与示例 apk](#效果图与示例-apk)
* [常见问题](#常见问题)
* [使用](#使用)
* [自定义属性说明](#自定义属性说明)
* [关于我](#关于我)
* [打赏支持](#打赏支持)
* [License](#license)

## 功能介绍

- [x] 引导界面导航效果
- [x] 支持根据服务端返回的数据动态设置广告条的总页数
- [x] 支持大于等于1页时的无限循环自动轮播、手指按下暂停轮播、抬起手指开始轮播
- [x] 支持自定义指示器位置和广告文案位置
- [x] 支持图片指示器和数字指示器
- [x] 支持 ViewPager 各种切换动画
- [x] 支持选中特定页面
- [x] 支持监听 item 点击事件
- [x] 加载网络数据时支持占位图设置,避免出现整个广告条空白的情况
- [x] 多个 ViewPager 跟随滚动

## 效果图与示例 apk

![banner](https://cloud.githubusercontent.com/assets/8949716/17557718/dc235ec4-5f4a-11e6-92b7-144a2a1a1e3f.gif)

[点击下载 BGABannerDemo.apk](http://fir.im/BGABannerDemo) 或扫描下面的二维码安装

![BGABannerDemo apk文件二维](http://bgashare.bingoogolapple.cn/banner/BGABannerDemo.png)

## 常见问题

1. 结合 Fresco 加载图片请参考 [FrescoDemoActivity](https://github.com/bingoogolapple/BGABanner-Android/blob/master/demo/src/main/java/cn/bingoogolapple/bgabanner/demo/ui/activity/FrescoDemoActivity.java)
2. 自定义 item 布局文件请参考 [FrescoDemoActivity](https://github.com/bingoogolapple/BGABanner-Android/blob/master/demo/src/main/java/cn/bingoogolapple/bgabanner/demo/ui/activity/FrescoDemoActivity.java)

## 使用

### 1.添加 Gradle 依赖

* 把 `maven { url 'https://jitpack.io' }` 添加到 root build.gradle 的 repositories 中
* 在 app build.gradle 中添加如下依赖,末尾的「latestVersion」指的是徽章 [![](https://jitpack.io/v/bingoogolapple/BGABanner-Android.svg)](https://jitpack.io/#bingoogolapple/BGABanner-Android) 里的版本名称,请自行替换

```groovy
implementation 'androidx.legacy:legacy-support-v4:latestVersion'
implementation 'com.github.bingoogolapple:BGABanner-Android:latestVersion'
```

### 2.在布局文件中添加 BGABanner

```xml

```

### 3.在 Activity 或者 Fragment 中配置 BGABanner 的数据源

有多种配置数据源的方式,这里仅列出三种方式。更多初始化方式请查看 [demo](https://github.com/bingoogolapple/BGABanner-Android/tree/master/demo)

>配置数据源的方式1:通过传入数据模型并结合 Adapter 的方式配置数据源。这种方式主要用于加载网络图片,以及实现少于3页时的无限轮播

```java
mContentBanner.setAdapter(new BGABanner.Adapter() {
@Override
public void fillBannerItem(BGABanner banner, ImageView itemView, String model, int position) {
Glide.with(MainActivity.this)
.load(model)
.placeholder(R.drawable.holder)
.error(R.drawable.holder)
.centerCrop()
.dontAnimate()
.into(itemView);
}
});

mContentBanner.setData(Arrays.asList("网络图片路径1", "网络图片路径2", "网络图片路径3"), Arrays.asList("提示文字1", "提示文字2", "提示文字3"));
```

> 配置数据源的方式2:通过直接传入视图集合的方式配置数据源,主要用于自定义引导页每个页面布局的情况

```java
List views = new ArrayList<>();
views.add(View.inflate(context, R.layout.layout_guide_one, null));
views.add(View.inflate(context, R.layout.layout_guide_two, null));
views.add(View.inflate(context, R.layout.layout_guide_three, null));
mContentBanner.setData(views);
```

> 配置数据源的方式3:通过传入图片资源 id 的方式配置数据源,主要用于引导页每一页都是只显示图片的情况

```
// Bitmap 的宽高在 maxWidth maxHeight 和 minWidth minHeight 之间
BGALocalImageSize localImageSize = new BGALocalImageSize(720, 1280, 320, 640);
// 设置数据源
mContentBanner.setData(localImageSize, ImageView.ScaleType.CENTER_CROP,
R.drawable.uoko_guide_background_1,
R.drawable.uoko_guide_background_2,
R.drawable.uoko_guide_background_3);
```

### 4.监听广告 item 的单击事件,在 BGABanner 里已经帮开发者处理了防止重复点击事件

```java
mContentBanner.setDelegate(new BGABanner.Delegate() {
@Override
public void onBannerItemClick(BGABanner banner, ImageView itemView, String model, int position) {
Toast.makeText(banner.getContext(), "点击了" + position, Toast.LENGTH_SHORT).show();
}
});
```

### 5.设置「进入按钮」和「跳过按钮」控件资源 id 及其点击事件,如果进入按钮和跳过按钮有一个不存在的话就传 0,在 BGABanner 里已经帮开发者处理了防止重复点击事件,在 BGABanner 里已经帮开发者处理了「跳过按钮」和「进入按钮」的显示与隐藏

```java
mContentBanner.setEnterSkipViewIdAndDelegate(R.id.btn_guide_enter, R.id.tv_guide_skip, new BGABanner.GuideDelegate() {
@Override
public void onClickEnterOrSkip() {
startActivity(new Intent(GuideActivity.this, MainActivity.class));
finish();
}
});
```

## 自定义属性说明
```xml






























































```

## 代码是最好的老师,更多详细用法请查看 [demo](https://github.com/bingoogolapple/BGABanner-Android/tree/master/demo):feet:

## 关于我

| 个人主页 | 邮箱 | BGA 系列开源库 QQ 群 | GitHub 喵(专注于 GitHub 等一切与程序员有关的内容) |
| ------------- | ------------ | ------------ | ------------ |
| bingoogolapple.cn | [email protected] | ![BGA_CODE_CLUB](http://bgashare.bingoogolapple.cn/BGA_CODE_CLUB.png?imageView2/2/w/200) | ![GitHub喵](https://user-images.githubusercontent.com/8949716/99201262-1fd55200-27e5-11eb-8097-c06d2497f477.jpeg) |

## 打赏支持

如果您觉得 BGA 系列开源库帮你节省了大量的开发时间,请扫描下方的二维码随意打赏,要是能打赏个 10.24 :monkey_face:就太:thumbsup:了。您的支持将鼓励我继续创作:octocat:

如果您目前正打算购买通往墙外的梯子,可以使用我的邀请码「YFQ9Q3B」购买 [Lantern](https://github.com/getlantern/forum),双方都赠送三个月的专业版使用时间:beers:



## License

Copyright 2015 bingoogolapple

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.