ScrollTo 方法没有用
我制作了一个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();
}
}
我认为这两种方法之间没有太大区别...但是为什么...
任何人都可以帮助我吗?
非常感谢。
I made a android program to read books.. And I want to make it possible to open a tag ,and when you open a tag, the program will open the book and scroll to the position which is told in the tag .
But in my app,the ScrollTo function seems no reaction .
Here is my code.
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...
The process in onCreate is not important ,so I delete them..
What is puzzling me is that in the method below the method scroll can work...
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();
}
}
I don't think there's so much difference between these two methods...But why...
Anyone can help me?
THX a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在你的 onCreate 尝试中
in your onCreate try