The Method ScrollTo has no use
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) {
sup开发者_如何学JAVAer.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.
in your onCreate try
text.post(new Runnable() {
@Override
public void run() {
text.scrollTo(...);
}
});
精彩评论