是否有任何库可以让我们在 recyclerview 中获得跑马灯效果(例如 hotstar vip 页面滚动图像)?

Is there any library from which we can we get marquee effect in recyclerview(e.g hotstar vip page scrolling images)?

Blockquote

我正在尝试像 hotstar 那样在 hotstar VIP 订阅页面中实现自动滚动无限 recyclerview。

我已经尝试了给定的代码。

对于自动滚动回收器:-

binding.rvPartyOfWeek.addOnScrollListener(CustomScrollListener())

private val SCROLLING_RUNNABLE = object : Runnable {
    override fun run() {
        val duration = 10
        val pixelsToMove = 22

        if (!isPartyOfWeekScrolling) {
            binding.rvPartyOfWeek.smoothScrollBy(pixelsToMove, 0)
        }
        mHandler.postDelayed(this, duration.toLong())
    }
}

对于无限滚动:-

binding.rvPartyOfWeek.addOnScrollListener(object : RecyclerView.OnScrollListener() {
            override fun onScrolled(recyclerView2: RecyclerView, dx: Int, dy: Int) {
                super.onScrolled(recyclerView2, dx, dy)
                val totalItemCount = layoutManagerparty.itemCount
                val lastVisibleItem = layoutManagerparty.findLastVisibleItemPosition()
                if (totalItemCount <= (lastVisibleItem + 3)) {
                    if (totalItemCount > 22) {
                        for (i in 0..10) {
                            listParty.removeAt(0)
                        }
                    }
                    listParty.addAll(listPartySingle)
                    adapterpartyofweek.notifyDataSetChanged()
                    Log.i("Helllo listParty", listParty.size.toString())
                }
            }
        })

在某些设备上滚动不流畅,在某些旧设备上会崩溃。

我做了如下操作:

  1. 为 RecyclerView 创建自动滚动

`

private fun autoScroll() {
        scrollCount = 0;
        var speedScroll: Long = 1200;
        val runnable = object : Runnable {
            override fun run() {
                if (layoutManager.findFirstVisibleItemPosition() >= imageArrayList.size / 2) {
                    adapter.load()
                }
                recyclerView.smoothScrollToPosition(scrollCount++)
                Log.e(TAG, "run: $scrollCount")
                handler.postDelayed(this, speedScroll)
            }
        }
        handler.postDelayed(runnable, speedScroll)
    }

`

  1. 自动创建平滑滚动

`

layoutManager = object : LinearLayoutManager(this@MainActivity) {
            override fun smoothScrollToPosition(recyclerView: RecyclerView, state: RecyclerView.State?, position: Int) {
                val smoothScroller = object : LinearSmoothScroller(this@MainActivity) {
                    override fun calculateSpeedPerPixel(displayMetrics: DisplayMetrics?): Float {
                        return 5.0f;
                    }
                }
                smoothScroller.targetPosition = position
                startSmoothScroll(smoothScroller)
            }
        }

`

有关源代码,请查看 GitHub 项目 link https://github.com/Mahesh2318/AutoScrollRecyclerView