是否可以将 ScrollView 滚动到底部? [英] Is it possible to keep a ScrollView scrolled to the bottom?
本文介绍了是否可以将 ScrollView 滚动到底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于类似聊天的应用程序,我希望将 ScrollView
组件滚动到底部,因为最新消息显示在旧消息下方.我们可以调整 ScrollView
的滚动位置吗?
For a chat-like app, I want to keep a ScrollView
component scrolled to the bottom, because newest messages appear under the older ones. Can we adjust the scroll position of a ScrollView
?
推荐答案
对于 React Native 0.41 及更高版本,您可以使用内置的 scrollToEnd
方法:
For React Native 0.41 and later, you can do this with the built-in scrollToEnd
method:
<ScrollView
ref={ref => {this.scrollView = ref}}
onContentSizeChange={() => this.scrollView.scrollToEnd({animated: true})}>
</ScrollView>
这篇关于是否可以将 ScrollView 滚动到底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文