修改股票代码
问题描述:
我试图修改下面的类,以便滚动文字出现在画面左下角的“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);
}
}
答
尝试修改你的paint方法是这样的:
protected void paint(Graphics graphics) {
graphics.drawBitmap(0, 0, backgroundImage.getWidth(), backgroundImage.getHeight(), backgroundImage, 0, 0);
graphics.setColor(Color.WHITE);
graphics.drawText(text, offset, 0);
Bitmap b = Bitmap.getBitmapResource("overlay.png");
graphics.drawBitmap(0, 0, b.getWidth(), b.getHeight(), b, 0, 0);
}
不要使用代号!他们违背了我能想到的每一个良好的UI设计原则! – 2011-04-09 00:16:24
我必须在这种情况下使用一个。 – 2011-04-09 00:23:48