我在字符串数组中有十个单词。例如:{“A B”,“C D”,“E F”,“G H”......}。 我必须连续显示这些单词,在屏幕上按住每个单词2秒钟。显示每个新单词时,字体大小也需要变小。
如何在BlackBerry上执行此操作?
答案 0 :(得分:0)
您可以使用Timer
来控制时间:
import java.util.Timer
int index;
String[] words;
...
TimerTask task = new TimerTask() {
public void run()
{
// TODO: Check the bounds and kill the timer when we're done.
// Invoke the code in the UI Thread
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run()
{
// Code to enumerate and concat the string...
}
});
}
};
timer timer = new Timer();
timer.scheduleAtFixedRate(task, 0, 2000);
更改字体大小:
// in the class body:
final int minFontSize = 5;
int maxFontSize = minFontSize + words.length();
// in the timer's run method:
net.rim.device.api.ui.Font defaultFont = this.getFont();
net.rim.device.api.ui.Font myFont = defaultFont.derive(0, maxFontSize - index)
// change the font of the ui control
field.setFont(myFont);
我没有检查代码是否编译,但我希望你明白这一点。