2011-03-02 46 views
1

我创建了滚动文本视图,并且已经能够添加文本并滚动得很好。事情是,我试图按时间间隔添加文本,并且可以通过点击屏幕底部的两个按钮之一来调整间隔。一切都已到位,但无论我做什么,我只能在整个持续时间后立即显示所有文本。假设我正在尝试每半秒添加文本十秒钟。运行它会导致10秒内没有任何结果,然后一切都显示出来。我尝试过/带有计数器的循环,并通过系统时间跟踪。不。递归会立刻吹出堆栈,这并不令人意外。无论如何,使用wait()或Thread.sleep()都不起作用,因为按钮必须始终处于活动状态。在私有内部类中创建单独的线程不起作用,因为您无法触摸在另一个线程中创建的视图。试图在单独的线程中创建自定义视图拒绝工作,原因我现在还不知道。以定时递增的方式添加滚动文本视图

我该怎么做,以便实时添加每个条目?

回答

0

在我的情况下,它工作正常的Autoscroling一个Timer对象沿

timer=new Timer(); 
scroll.setSmoothScrollingEnabled(true); 
scroll.pageScroll(ScrollView.FOCUS_DOWN); 
scroll.smoothScrollTo(0, text.getBaseline()); 
x=text.getBaseline(); 
Toast.makeText(scoruby.this,"number"+x++, Toast.LENGTH_SHORT).show(); 

timer.schedule(new TimerTask() { 

@Override 
public void run() { 
    TimerMethod(); 


} 
}, 0,1000); 
} 
private void TimerMethod() 
{ 
//This method is called directly by the timer 
//and runs in the same thread as the timer. 

//We call the method that will work with the UI 
//through the runOnUiThread method. 
this.runOnUiThread(Timer_Tick); 
} 

private Runnable Timer_Tick = new Runnable() { 
public void run() { 
    x+=5; 
    scroll.smoothScrollTo(0, x++); 



} 
}; 
相关问题