/Banner

🪧 Banner is an library for ad view that implements automatic slide effects using ViewPager2.

Primary LanguageKotlinApache License 2.0Apache-2.0

Banner


🪧 Banner is an library for ad view that implements automatic slide effects using ViewPager2.

License

Dependency Gradle

Add below codes to your root build.gradle file (not your module build.gradle file).

allprojects {
  repositories {
      jcenter()
      maven { url "https://jitpack.io" }
  }
}

And add a dependency code to your module's build.gradle file.

dependencies {
implementation 'com.github.KennethSS:Banner:1.0.2'
}

Usage

<com.solar.kenneth.banner.BannerView
  android:id="@+id/banner_view"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  app:ratio_width="18"
  app:ratio_height="13"
  app:infinity="true"
  app:autoScroll="true"/>
bannerView.addBannerViewListener(object: BannerViewListener {
    override fun onBannerBinding(iv: ImageView, banner: Banner) {
      // Something to load for image
    }
  })

UseCase RecyclerView

class RecyclerViewAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
  override fun onViewRecycled(holder: RecyclerView.ViewHolder) {
  if (holder is BannerViewHolder) {
    holder.recycled()
  }
  super.onViewRecycled(holder)
  }
}

class BannerViewHolder(view: View) : RecyclerView.ViewHolder(view) { 
  init {
    bannerView.addBannerViewListener(object: BannerViewListener {
      override fun onBannerBinding(iv: ImageView, banner: Banner) {

      }
    })

    bannerView.setBannerList(lists)
  }

  fun bind() {
    bannerView.startAutoSlide()
  }

  fun recycled() {
    bannerView.stopAutoSlide()
  }
}