ScrollView滚动到顶部或者底部

今天遇到了一个需要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可以实现这种需求。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容