How can i control the scrolling speed of recyclerView.smoothScrollToPosition(position)

前端 未结 5 612
感情败类
感情败类 2020-11-28 23:18

I have a recycler view... and i want a smooth scrolldown and then scrollup to it programatically to show the complete content in it to user .... And i m able to do this by<

5条回答
  •  旧巷少年郎
    2020-11-28 23:54

    I got it like this horizontally

      private val milliSecondsPerInch = 500f 
      var horizontalLayoutManager =  LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
    

    onCreate

    horizontalLayoutManager =  LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
    recycler_banner?.layoutManager = horizontalLayoutManager
    

    and then

    val linearSmoothScroller: LinearSmoothScroller =
    object : LinearSmoothScroller(this) {
        override fun calculateSpeedPerPixel(displayMetrics: DisplayMetrics): Float {
            return milliSecondsPerInch / displayMetrics.densityDpi
        }
    }
    linearSmoothScroller.targetPosition = 3 //the last position of the item in the list
    horizontalLayoutManager.startSmoothScroll(linearSmoothScroller)
    

提交回复
热议问题