有没有我们可以在recyclerview中获得字幕效果的库?

块引用


我正在尝试实现自动滚动无限 recyclerview,就像 hotstar 在 hotstar VIP 订阅页面中拥有它一样。


我试过给定的代码。


对于自动滚动回收器:-


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())

                }

            }

        })

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


aluckdog
浏览 105回答 1
1回答

繁星coding

我做了如下:为 RecyclerView 创建自动滚动`private fun autoScroll() {&nbsp; &nbsp; &nbsp; &nbsp; scrollCount = 0;&nbsp; &nbsp; &nbsp; &nbsp; var speedScroll: Long = 1200;&nbsp; &nbsp; &nbsp; &nbsp; val runnable = object : Runnable {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; override fun run() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (layoutManager.findFirstVisibleItemPosition() >= imageArrayList.size / 2) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; adapter.load()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; recyclerView.smoothScrollToPosition(scrollCount++)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Log.e(TAG, "run: $scrollCount")&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; handler.postDelayed(this, speedScroll)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; handler.postDelayed(runnable, speedScroll)&nbsp; &nbsp; }`自动创建平滑滚动`layoutManager = object : LinearLayoutManager(this@MainActivity) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; override fun smoothScrollToPosition(recyclerView: RecyclerView, state: RecyclerView.State?, position: Int) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; val smoothScroller = object : LinearSmoothScroller(this@MainActivity) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; override fun calculateSpeedPerPixel(displayMetrics: DisplayMetrics?): Float {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 5.0f;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; smoothScroller.targetPosition = position&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; startSmoothScroll(smoothScroller)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }`对于源代码,查看 GitHub 项目链接 https://github.com/Mahesh2318/AutoScrollRecyclerView
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java