我有一个textview活动,其中打印了某个文件。我需要将其自动滚动到最后。下面的代码在onCreate中不起作用,但是当我从该活动的屏幕上的按钮(onClick)调用相同的方法(最后两行)时,每个都可以正常工作。你能告诉我诀窍在哪里吗?
代码:
public class LogViewer extends AndroidClientBase implements OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!hasWindowFocus()) {
setContentView(R.layout.log_viewer);
}
TextView myHelpTV = (TextView) findViewById(R.id.textLog);
myHelpTV.setMovementMethod(LinkMovementMethod.getInstance());
myHelpTV.scrollTo(0,0);
// set button listeners
// that part (see below) works fine in onClick, but not in
//onCreate, onStart or onResume:
//read some text to textview...
//scroll down scrollview wrapper
ScrollView myHelpSV = (ScrollView) findViewById(R.id.logScrollView1);
myHelpSV.fullScroll(View.FOCUS_DOWN);
}
它可能是什么?提前感谢您的建议!
答案 0 :(得分:1)
是的,通常使用Runnable来解决这个问题 - 感谢atraudes! How to scroll to bottom in a ScrollView on activity startup