如何在活动启动时滚动到 ScrollView 的底部 [英] How to scroll to bottom in a ScrollView on activity startup
问题描述
我正在 ScrollView 中显示一些数据.在活动启动时(方法 onCreate),我用数据填充 ScrollView 并希望滚动到底部.
I am displaying some data in a ScrollView. On activity startup (method onCreate) I fill the ScrollView with data and want to scroll to the bottom.
我尝试使用 getScrollView().fullScroll(ScrollView.FOCUS_DOWN)
.当我将其作为按钮单击操作时,此方法有效,但在 onCreate 方法中无效.
I tried to use getScrollView().fullScroll(ScrollView.FOCUS_DOWN)
. This works when I make it as an action on button click but it doesn't work in the onCreate method.
有什么方法可以在活动启动时将 ScrollView 滚动到底部?这意味着第一次显示时视图已经滚动到底部.
Is there any way how to scroll the ScrollView to the bottom on activity startup? That means the view is already scrolled to the bottom when first time displayed.
推荐答案
需要做如下:
getScrollView().post(new Runnable() {
@Override
public void run() {
getScrollView().fullScroll(ScrollView.FOCUS_DOWN);
}
});
这种方式首先更新视图,然后滚动到新"底部.
This way the view is first updated and then scrolls to the "new" bottom.
这篇关于如何在活动启动时滚动到 ScrollView 的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!