Android中ScrollTo与ScrollBy的区别
经过查看源码,ScrollBy方法中通过调用ScrollTo实现
ScrollTo每次都回到原点然后进行移动
ScrollBy是在上一次移动的距离基础上进行移动
var mDownY = 0f;
var mMoveY = 0;
override fun onTouchEvent(event: MotionEvent?): Boolean {
when (event?.action) {
MotionEvent.ACTION_DOWN -> {
mDownX = event.x
mDownY = event.y
}
MotionEvent.ACTION_MOVE -> {
// scrollBy(0, (mDownY - event.y).toInt())
scrollTo(0, mMoveY + (mDownY - event.y).toInt())
mMoveY = scrollY
}
}
return true
}
网友评论