Android Kotlin - 当 NestedScrollView 停止滚动时检测/监听
Android Kotlin - detect / listen when NestedScrollView stops scrolling
这是我目前拥有的:
holder.scrollView.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
Log.d(tagg, "$scrollY")
})
我想检测滚动停止的时间,然后获取 scrollY
,该怎么做?
好的,我就是这样解决的:
private var countDownTimer: CountDownTimer? = null
private fun lastPosUpdate(memeID: Long, scrollPos: Int){
if(countDownTimer != null){
countDownTimer!!.cancel()
}
countDownTimer = object: CountDownTimer(300, 300) {
override fun onTick(millisUntilFinished: Long) {
}
override fun onFinish() {
Log.d(tagg, "scroll finished")
}
}
countDownTimer!!.start()
}
holder.scrollView.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
lastPosUpdate(meme.id, scrollY)
})
这是我目前拥有的:
holder.scrollView.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
Log.d(tagg, "$scrollY")
})
我想检测滚动停止的时间,然后获取 scrollY
,该怎么做?
好的,我就是这样解决的:
private var countDownTimer: CountDownTimer? = null
private fun lastPosUpdate(memeID: Long, scrollPos: Int){
if(countDownTimer != null){
countDownTimer!!.cancel()
}
countDownTimer = object: CountDownTimer(300, 300) {
override fun onTick(millisUntilFinished: Long) {
}
override fun onFinish() {
Log.d(tagg, "scroll finished")
}
}
countDownTimer!!.start()
}
holder.scrollView.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
lastPosUpdate(meme.id, scrollY)
})