亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

有沒有我們可以在recyclerview中獲得字幕效果的庫?

有沒有我們可以在recyclerview中獲得字幕效果的庫?

aluckdog 2022-12-07 14:26:58
塊引用我正在嘗試實現自動滾動無限 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())                }            }        })它在某些設備上滾動不流暢,在某些舊設備上崩潰。
查看完整描述

1 回答

?
繁星coding

TA貢獻1797條經驗 獲得超4個贊

我做了如下:


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

    }

`


自動創建平滑滾動

`


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 項目鏈接 https://github.com/Mahesh2318/AutoScrollRecyclerView


查看完整回答
反對 回復 2022-12-07
  • 1 回答
  • 0 關注
  • 117 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號