0
我試圖修改下面的類,以便滾動文字出現在畫面左下角的「overlay.png」圖像後面。修改股票代碼
我試圖改變
final int screenWidth = Display.getWidth();
到
final int screenWidth = 240
但did'nt工作。
我該如何採取行動?
感謝
public class Ticker extends Field {
String text;
final int screenWidth = Display.getWidth();
int offset = screenWidth;
Timer timer = new Timer();
final int delay = 20;
private Bitmap backgroundImage;
public void setText(String text) {
this.text = text;
}
public String getText() {
return text;
}
public Ticker(String text) {
this.text = text;
backgroundImage = Constants.TICKER_BACKGROUND_IMAGE;
final int width = Font.getDefault().getAdvance(text);
TimerTask timerTask = new TimerTask() {
public void run() {
offset--;
if (offset + width == 0) {
offset = screenWidth;
}
invalidate();
}
};
timer.scheduleAtFixedRate(timerTask, delay, delay);
}
protected void layout(int width, int height) {
int w = Display.getWidth();
int h = Font.getDefault().getHeight();
setExtent(w, h);
}
protected void paint(Graphics graphics) {
graphics.drawBitmap(0, 0, backgroundImage.getWidth(), backgroundImage.getHeight(), backgroundImage, 0, 0);
Bitmap b = Bitmap.getBitmapResource("overlay.png");
graphics.drawBitmap(0, 0, b.getWidth(), b.getHeight(), b, 0, 0);
graphics.setColor(Color.WHITE);
graphics.drawText(text, offset, 0);
}
}
不要使用代號!他們違背了我能想到的每一個良好的UI設計原則! – 2011-04-09 00:16:24
我必須在這種情況下使用一個。 – 2011-04-09 00:23:48