今天遇到了一个需要ScrollView在事件触发后跳转到顶端,查询了一下有使用ScrollView中void scrollTo (int x,int y)这个方法的,尝试了一下是可以实现的,但是如果是滑动到底部呢,所以这个方法明显有点无力,查找了下官网找到了一个方法
fullScroll(int direction)
directionint: the scroll direction:FOCUS_UPto go the top of the view orFOCUS_DOWNto go the bottom
developer.android.com/reference/android/widget/ScrollView.html#fullScroll(int)
Handles scrolling in response to a "home/end" shortcut press. This method will scroll the view to the top or bottom and give the focus to the topmost/bottommost component in the new visible area. If no component is a good candidate for focus, this scrollview reclaims the focus.
大概意思就是:一个滚动到底部和顶部的快捷方式,传递的参数为FOCUS_UP或者FOCUS_DOWN可以实现这种需求。
网友评论