XBanner
支持圖片無限輪播的控件,可進(jìn)行自定義功能。
主要功能:
- 支持根據(jù)服務(wù)端返回的數(shù)據(jù)動態(tài)設(shè)置廣告條的總頁數(shù)
- 支持大于等于1頁時的無限循環(huán)自動輪播、手指按下暫停輪播、抬起手指開始輪播
- 支持自定義狀態(tài)指示點位置 左 、中 、右
- 支持自定義狀態(tài)指示點
- 支持監(jiān)聽 item 點擊事件
- 支持設(shè)置圖片輪播間隔
- 支持指示器背景的修改及隱藏/顯示
- 支持顯示提示性文字功能
- 支持圖片切換動畫,目前支持10種切換動畫,具體可看demo
- 支持設(shè)置圖片切換速度
- 支持設(shè)置數(shù)字指示器
- 支持Glide/Fresco等主流圖片加載框架加載圖片
效果圖

xbanner.gif
基本使用
1.添加Gradle依賴
dependencies {
compile 'com.xhb:xbanner:1.3.1'
}
或者libs文件夾添加xbanner-1.3.1.aar
repositories {
flatDir {
dirs 'libs'
}
}
compile(name: 'xbanner-1.3.1', ext: 'aar')
2.在清單文件中添加網(wǎng)絡(luò)權(quán)限
<uses-permission android:name="android.permission.INTERNET" />
3.在布局文件中添加XBanner
<com.stx.xhb.xbanner.XBanner
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/banner_1"
android:layout_width="match_parent"
android:layout_height="180dp"
app:AutoPlayTime="3000"
app:pointsContainerBackground="#44aaaaaa"
app:pointNormal="@drawable/shape_noraml"
app:pointSelect="@drawable/shape_selected"
app:pointsPosition="RIGHT"
app:tipTextSize="12sp"
app:isShowNumberIndicator="true"
app:isShowIndicatorOnlyOne="true"
app:pageChangeDuration="800"/>
4.在Activity或者Fragment中配置
初始化:直接傳入視圖集合進(jìn)行初始化
List<String> imgesUrl = new ArrayList<>();
imgesUrl.add("http://img3.fengniao.com/forum/attachpics/913/114/36502745.jpg");
imgesUrl.add("http://imageprocess.yitos.net/images/public/20160910/99381473502384338.jpg");
imgesUrl.add("http://imageprocess.yitos.net/images/public/20160910/77991473496077677.jpg");
imgesUrl.add("http://imageprocess.yitos.net/images/public/20160906/1291473163104906.jpg");
//添加廣告數(shù)據(jù)
mBannerNet.setData(imgesUrl,null);//第二個參數(shù)為提示文字資源集合
5.加載廣告
可根據(jù)自己項目需要使用相應(yīng)的圖片加載工具進(jìn)行加載圖片,此處使用Glide,進(jìn)行加載,可配置占位圖等
mBannerNet.setmAdapter(this);
@Override
public void loadBanner(XBanner banner, View view, int position) {
Glide.with(this).load(imgesUrl.get(position)).into((ImageView) view);
}
6.監(jiān)聽廣告 item 的單擊事件
mBannerNet.setOnItemClickListener(new XBanner.OnItemClickListener() {
@Override
public void onItemClick(XBanner banner, int position) {
Toast.makeText(MainActivity.this, "點擊了第"+position+"圖片", Toast.LENGTH_SHORT).show();
}
});
7.為了更好的體驗,建議j在添加以下代碼
/** 為了更好的體驗效果建議在下面兩個生命周期中調(diào)用下面的方法 **/
@Override
protected void onResume() {
super.onResume();
mXBanner.startAutoPlay();
}
@Override
protected void onStop() {
super.onStop();
mXBanner.stopAutoPlay();
}
8.當(dāng)使用Fresco加載圖片時,需要自定義布局文件
1.自定義xml布局文件 image_fresco.layout
<?xml version="1.0" encoding="utf-8"?>
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/my_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
2.使用setData()方法進(jìn)行設(shè)置
mXBanner.setData(R.layout.image_fresco.layout,mOthersList,tips);
自定義屬性說明
| 屬性名 | 屬性說明 | 屬性值 |
|---|---|---|
| isAutoPlay | 是否支持自動輪播 | boolean類型,默認(rèn)為true |
| isTipsMarquee | 是否支持提示性文字跑馬燈效果 | boolean類型,默認(rèn)為false |
| AutoPlayTime | 圖片輪播時間間隔 | int值,默認(rèn)為5s |
| pointNormal | 指示器未選中時狀態(tài)點 | drawable,不設(shè)置的話為默認(rèn)狀態(tài)點 |
| pointSelect | 指示器選中時狀態(tài)點 | drawable,不設(shè)置的話為默認(rèn)狀態(tài)點 |
| pointsVisibility | 是否顯示指示器 | boolean類型,默認(rèn)為true |
| pointsPosition | 指示點顯示位置 | LEFT、CENTER、RIGHT類型,默認(rèn)為CENTER |
| pointsContainerBackground | 指示器背景 | 可自定義設(shè)置指示器背景 |
| pointContainerPosition | 指示器顯示位置 | TOP、BOTTOM類型,默認(rèn)為BOTTOM |
| pointContainerLeftRightPadding | 指示點容器左右內(nèi)間距 | dimension,默認(rèn)為10dp |
| pointTopBottomPadding | 指示點上下內(nèi)間距 | dimension,默認(rèn)為6dp |
| pointLeftRightPadding | 指示點左右內(nèi)間距 | dimension,默認(rèn)為3dp |
| tipTextColor | 提示文案的文字顏色 | reference |
| tipTextSize | 提示文案的文字大小 | dimension,默認(rèn)為10dp |
| isShowNumberIndicator | 是否顯示數(shù)字指示器 | boolean,默認(rèn)為false不顯示 |
| numberIndicatorBacgroud | 數(shù)字指示器背景 | reference |
| isShowIndicatorOnlyOne | 當(dāng)只有一張圖片的時候是否顯示指示點 | boolean,默認(rèn)為false,不顯示 |
| pageChangeDuration | 圖片切換速度 | int值,默認(rèn)為1000ms |
混淆配置
##XBanner 圖片輪播混淆配置
-keep class com.stx.xhb.xbanner.**{*;}