android – 方法ScrollTo没用

android – 方法ScrollTo没用,第1张

概述我制作了一个 Android程序来阅读书籍.我希望能够打开一个标签,当你打开一个标签时,程序将打开书并滚动到标签中告知的位置. 但在我的应用程序中,ScrollTo函数似乎没有反应. 这是我的代码. protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 我制作了一个 Android程序来阅读书籍.我希望能够打开一个标签,当你打开一个标签时,程序将打开书并滚动到标签中告知的位置.

但在我的应用程序中,ScrollTo函数似乎没有反应.

这是我的代码.

protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.reader);        scrollVIEw = (ScrollVIEw)findVIEwByID(R.ID.Scroll);        text       = (TextVIEw)findVIEwByID(R.ID.text);        Tagsbutton = (Imagebutton)findVIEwByID(R.ID.Tags);        openbutton = (Imagebutton)findVIEwByID(R.ID.Open);        text.setTextcolor(color.RED);        text.scrollTo(0,index);    }//Here the scrollTo do not work...

onCreate中的过程并不重要,所以我删除了它们.

令我困惑的是,在下面的方法中,方法滚动可以工作…

protected voID onActivityResult(int requestCode,int resultCode,Intent data) {        super.onActivityResult(requestCode,resultCode,data);        if(data!=null){        Bundle bundle = data.getExtras();        if(bundle!=null){        int index = bundle.getInt("Index");        String file_name = bundle.getString("file_name");        Readfile(file_name);        scrollVIEw.scrollTo(0,index);        text.postInvalIDate();        }        }

我不认为这两种方法之间存在太大差异……但为什么……

有人可以帮帮我吗?

多谢.

解决方法 在你的onCreate尝试

text.post(new Runnable() {        @OverrIDe        public voID run() {              text.scrollTo(...);        }    });
总结

以上是内存溢出为你收集整理的android – 方法ScrollTo没用全部内容,希望文章能够帮你解决android – 方法ScrollTo没用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1129573.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存