我制作了一个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...
Run Code Online (Sandbox Code Playgroud)
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();
}
}
Run Code Online (Sandbox Code Playgroud)
我不认为这两种方法之间存在太大差异......但为什么......
有人可以帮帮我吗?
多谢.
在你的onCreate尝试
text.post(new Runnable() {
@Override
public void run() {
text.scrollTo(...);
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1125 次 |
| 最近记录: |