如何以编程方式滚动滚动型到底部 [英] How to Programmatically Scroll a ScrollView to Bottom

查看:116
本文介绍了如何以编程方式滚动滚动型到底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我解决不了:里面滚动型我只有一个 的LinearLayout。通过用户操作我编程加入2的TextView 在此的LinearLayout,而是由默认滚动保持在顶部。 因为我控制研究用户行为,我应该很容易滚动到 底部的东西,如:

I've a problem I can't solve: inside a ScrollView I only have a LinearLayout. By a user action I'm programmatically adding 2 TextView on this LinearLayout, but by the default the scroll keeps on the top. Since I controll the user action, I should be easy to scroll to the bottom with something like:

ScrollView scroll = (ScrollView) this.findViewById(R.id.scroll);
scroll.scrollTo(0, scroll.getBottom());

但实际上并非如此。由于添加此两个新的后 元素getBottom()仍返回previous两种。我尝试过了 刷新状态调用 refreshDrawableState(),但我不工作。

But actually not. Because immediately after adding this two new elements getBottom() still returns the previous two. I tried to refresh the state invoking refreshDrawableState(), but I doesn't work.

你有什么想法,我怎么能获取滚动的实际底部 之后加入一些元素?

Do you have any idea how could I get the actual bottom of a ScrollView after adding some elements?

推荐答案

这实际上并没有解决你的问题。 但是,这其中pretty的多少做同样的事情。一个另外的

This doesn't actually solve your question. But it's an alternative which pretty much does the same thing.

相反滚动到屏幕的底部,焦点改变到其位于屏幕的底部的图。

Instead of Scrolling to the bottom of the screen, change the focus to a view which is located at the bottom of the screen.

也就是说,替换:

scroll.scrollTo(0, scroll.getBottom());

Footer.requestFocus();

请确保您指定的观点,说页脚可获得焦点。

Make sure you specify that the view, say 'Footer' is focusable.

android:focusable="true"
android:focusableInTouchMode="true"

这篇关于如何以编程方式滚动滚动型到底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆