Code Monkey home page Code Monkey logo

loopbanner's Introduction

LoopBanner

LoopBanner是通过自定义RecyclerView.LayoutManager以及PagerSnapHelper配合RecyclerView实现的可横向无限循环滑动的banner,详细的实现方法可查看博客:https://blog.csdn.net/ww897532167/article/details/86585214

添加依赖

  1. project 的 build.gradle
allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}
  1. module 的 build.gradle
dependencies {
    implementation 'com.github.WenWangAndroid:LoopBanner:1.0'
}

基本使用

recyclerView.adapter = imageAdapter
recyclerView.layoutManager = HorizontalLayoutManager()
val snapHelper = ViewPagerSnapHelper().apply {
    attachToRecyclerView(recyclerView)
}

RecyclerView滑动监听

recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {

            override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
                super.onScrollStateChanged(recyclerView, newState)
                when (newState) {
                    //The RecyclerView is not currently scrolling.
                    RecyclerView.SCROLL_STATE_IDLE -> {
                        val view = snapHelper.findSnapView(recyclerView.layoutManager) ?: return
                        val position = recyclerView.getChildAdapterPosition(view)
                        Log.i("TAG", "-----------position$position")
                    }
                    //The RecyclerView is currently being dragged
                    RecyclerView.SCROLL_STATE_DRAGGING -> {
                    }
                    //The RecyclerView is currently animating
                    RecyclerView.SCROLL_STATE_SETTLING -> {
                    }
                }
            }
        })

loopbanner's People

Contributors

xhu-ww avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.