我有一个滚动视图很长的活动。它与各个领域的一种形式,用户必须填写。我有一个复选框一半时我的形式,当用户检查它,我要滚动到视图的特定部分。有没有什么办法可以滚动到一个EditText对象(或任何其他视图对象)编程?
另外,我知道这是可能使用X和Y COORDS,但我想避免这样的形式可以改变从用户到用户。
解决方案 私人最终无效focusOnView(){
新的处理程序()。后(新的Runnable(){
@覆盖
公共无效的run(){
your_scrollview.scrollTo(0,your_EditBox.getBottom());
}
});
}
I have a very long activity with a scrollview. It is a form with various fields that the user must fill in. I have a checkbox half way down my form, and when the user checks it I want to scroll to a specific part of the view. Is there any way to scroll to an EditText object (or any other view object) programmatically?
Also, I know this is possible using X and Y coords but I want to avoid doing this as the form may changed from user to user.
解决方案private final void focusOnView(){
new Handler().post(new Runnable() {
@Override
public void run() {
your_scrollview.scrollTo(0, your_EditBox.getBottom());
}
});
}