I'm making a project in Kotlin that has a view with a long text inside a recyclerView. I wanted to put a linear progress bar to show how much text is left.
Currently I have this:
binding.rvBody.setOnScrollChangeListener { _, _, _, _, oldScrollY ->
// se computa el valor absoluto (queremos que total sea positivo)
val total = binding.rvBody.height
binding.progressBar?.apply {
max = total
progress += -oldScrollY
}
// si está arriba, el valor será 0
if (!binding.rvBody.canScrollVertically(-1)) { // si no se puede hacer scroll hacia arriba
binding.progressBar?.setProgressCompat(0, true)
}
// si está abajo, el valor será el total
if (!binding.rvBody.canScrollVertically(1)) { // si no se puede hacer scroll hacia abajo
binding.progressBar?.setProgressCompat(total, true)
}
}
The progressBar right now is moving as scrolling, but it gets to the end of the bar before getting to the end of the text, and it goes back to the begining of the bar also before getting to the begining again.
I had the same functionality working, I have a scroll view instead of a recycler view.
scroll is the id of ScrollView and progress is the ProgressBar
This code is working perfectly hope it works at your end too :)