我试图修改下面的类,以便滚动文本出现在屏幕左下角绘制的“overlay.png”图像后面。
我尝试过更改
final int screenWidth = Display.getWidth();
到
final int screenWidth = 240
但是没有工作。
我该如何解决这个问题?
谢谢
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);
}
}
答案 0 :(得分:0)
尝试修改你的绘画方法:
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 );
}