有没有办法以编程方式将滚动视图滚动到特定的编辑文本? [英] Is there a way to programmatically scroll a scroll view to a specific edit text?

查看:24
本文介绍了有没有办法以编程方式将滚动视图滚动到特定的编辑文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很长的滚动视图活动.这是一个包含用户必须填写的各种字段的表单.我在表单的中间有一个复选框,当用户选中它时,我想滚动到视图的特定部分.有没有办法以编程方式滚动到 EditText 对象(或任何其他视图对象)?

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?

另外,我知道这可以使用 X 和 Y 坐标,但我想避免这样做,因为表单可能会因用户而异.

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(){
        your_scrollview.post(new Runnable() {
            @Override
            public void run() {
                your_scrollview.scrollTo(0, your_EditBox.getBottom());
            }
        });
    }

这篇关于有没有办法以编程方式将滚动视图滚动到特定的编辑文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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