支持无限轮播的广告插件,提供 gif 动图支持。

XBanner

项目地址:AbbyJM/XBanner 

简介:支持无限轮播的广告插件,提供 gif 动图支持。

更多:作者   提 Bug   

标签:

广告轮播-gif-轮播-viewpager-无限轮播-

中文版 | English 

This is a banner suppoted gifs and images.无限轮播的广告控件,提供 gif 支持。

Introduction

A banner for showing Ads with the Viewpager and supports automatic play in an infinite loop.With XBanner you can customize the style of this banner.XBanner also provides gif supprot,and we use the 3rd party dependency to load gifs for better perfoemance.

Effects

The final effect is as the gif below.

Customize your banner style now.

  

Gradle

dependencies{

  compile 'com.abby.app:xbanner:1.5.7' //the latest version

  //Thans koral-- for android-gif-drawable,it's a good solution for showing gif images.It is high performance.
  //Instead of using ImageView+Glide,we use gif-drawable for better performance
  //The dependency 'pl.droidsonroids.gif:android-gif-drawable:1.2.8' was added in this project.
}

Usage

A simple way to use XBanner is like below. releaseBanner() must be called when the view is destroying

@Override
public void onCreate(Bundle savedInstanceState) {
   int[] res={R.drawable.pic1,R.drawable.pic2,R.drawable.pic3,R.drawable.pic4,R.drawable.pic5};
    xbanner.isAutoPlay(false)
           .setDelay(3000)
           .setImageRes(res)
           .start(); 
   }

@Override
public void onDestroy(){
super.onDestroy();     
xbanner.releaseBanner(); // releaseBanner() must be called when the view is destroying
}

A simple way to use XBanner with titles.BannerType must be set to TITLE_TYPES when using titles.

@Override
public void onCreate(Bundle savedInstanceState) {
int[] res={R.drawable.pic1,R.drawable.pic2,R.drawable.pic3,R.drawable.pic4,R.drawable.pic5};
List<String> titles=Arrays.asList("This is the picture 1","This is the picture 2","This is the picture 3","This is the picture 4","This is the picture 5");
  xbanner.isAutoPlay(false)
         .setBannerTypes(XBanner.NUM_INDICATOR_TITLE)//must set banner type to title type to avoid some logic error
         .setDelay(3000)
         .setImageRes(res)
         .setTitles(titles)// setImageResAndTitles(res,titles) also OK
         .start(); 
 }

@Override
public void onDestroy(){
    super.onDestroy();     
    xbanner.releaseBanner();// releaseBanner() must be called when the view is destroying
}

If you want to load images from the url,an ImageLoader will be needed.A simple way to use ImageLoader is like below.

@Override
public void onCreate(Bundle savedInstanceState) {
List<String> imageUrls=new ArrayList<>();
imageUrls.add("http://img2.tgbusdata.cn/v2/thumb/jpg/YzQ0NSw4MzAsNjQwLDQsMywxLC0xLDAscms1MA==/u/olpic.tgbusdata.cn/uploads/allimg/160324/238-160324160031.jpg");
imageUrls.add("http://img2.tgbusdata.cn/v2/thumb/jpg/ZjliZCw4MzAsNjQwLDQsMywxLC0xLDAscms1MA==/u/olpic.tgbusdata.cn/uploads/allimg/160324/238-160324160031-50.jpg");
xbanner.isAutoPlay(false)
     .setDelay(3000)
     .setImageUrls(imageUrls)
     //.asGif() if you want to load gif,call it
     .setImageLoader(new AbstractUrlLoader() {
      @Override
      /**
       *the one using Glide,you can customize your ImageLoader
       *when loading gifs,a default ImageLoader will be applied,which you don't need to add one
       *but if you want to customize your loader,do it
       */
      public void loadImages(Context context, String url, ImageView image) {
          Glide.with(context)   
                  .load(url)
                  .into(image);
      }

      @Override
      public void loadGifs(String url, GifImageView gifImageView, ImageView.ScaleType scaleType) {

      }
}).start(); 
}

@Override
public void onDestroy(){  
   super.onDestroy();  
    xbanner.releaseBanner();// releaseBanner() must be called when the view is destroying
}

A simple way to load gifs

@Override
public void onCreate(Bundle savedInstanceState) {
    banner.setImageUrls(gifUrls)
    .asGif()
    .setLoadingProgressType(XBanner.CIRCLE_PROGRESS)  //now you can apply a loading progress view here
    .start();
}

@Override
public void onDestroy(){  
   super.onDestroy();  
    xbanner.releaseBanner();// releaseBanner() must be called when the view is destroying
}

Feature(Methods)

namedescriptionparams
setBannerTypesset the type of banner,CIRCLEINDICATOR by defaultCIRCLE_INDICATOR,CIRCLE_INDICATOR_TITLE,CUBE_INDICATOR,NUM_INDICATOR,NUM_INDICATOR_TITLE
setIndicatorGravityset the gravity of indicators,CENTER by defaultINDICATOR_START,INDICATOR_CENTER,INDICATOR_END
setUpIndicatorSizeset up the size of indicators,IN PX,BOTH SELECTED AND UNSELECTED will be setint indicatorSize
setUpIndicatorsset up the indicator resIDint res_selected,int res_unselected
setEllipsizeTypeset the ellipsizetype of the title text,,END by defaultELLIPSIZE_END,ELLIPSIZE_MARQUEE
setImageScaleTypeset the scale type of the image,this method must be called before setting up the images,FIT_XY by defaultImageView.ScaleType scaleType
setScrollerset the scroller of the viewpagerthe scroller to be applied
setTitlebgAlphaset the title background to be alphano params
setImageResset the image resourceint[] res
setImageUrlsset the image urlsList< String > urls
setTitlesset the titlesList< String > titles
setImageResAndTitlesset the imageres and titlesint[] res,List< String > titles
setImageUrlsAndTitlesset the image urls and titlesList< String > urls,List< String > titles
setPageTransformerset the transformer for the viewpagerPageTransformer transformer
setDelayset the interval of the banner when playing,IN MSint delay
isAutoPlayindicate if the banner is automatically playingboolean is autoPlay
setTransformerSpeedset the transform speed when idle,IN MSint speed
setTitleHeightset the height of title,IN PXint height
setBannerPageListenerset the banner listenerBannerPageListener listener
getViewPagerget the viewPager of the bannerno params
asGifindicate the urls are gif urlsno params
clearGifCacheclear the cache of gifsno params
autoDeleteGifCacheautomatically delete the cache of gifs when reach the the given sizeint sizeInMB
startstart the banner,must be set to start the bannerno params
setLoadingProgressTypeset a progress view when loading gifsCIRCLE_PROGRESS or TEXT_PROGRESS
notifyDataSetChangedrefresh data after recalling setImageUrls and setImageResno params

Notice

  • if the images do not display,check out your network permission and your image if they are configured correctly
  • must set the banner type to TITLE TYPE when we set titles to avoid some logic errors
  • setImageScaleType must be called before we set the images
  • set an ImageLoader when loading images from url,but if you are loading gifs,you don't really have to
  • must call asGif() after you set the Url with setImageUrls method when loading gif,no need to set an ImageLoader if so
  • must call releaseBanner() in onDestroy()
  • to get a better visaul effect,indicator gravity is set to END when in TITLE mode
  • just confirm that your gif is in a correct format when you are downloading gif,or it won't be displayed
  • when refreshing data at run time,you should call notifyDataSetChanged() and you should reconfig the bannerPageListener because the listener is base on the position not the image itself,only image supports refresh,gif does not beacuse the cost is huge
  • supports API 19 and above
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值