修改股票代码
我尝试修改下面的类,以便滚动文本出现在绘制在屏幕左下角的“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);
}
}
Im trying to modify the class below so that the scrolling text appears behind the "overlay.png" image which is painted on the below left corner of screen.
I tried changing
final int screenWidth = Display.getWidth();
to
final int screenWidth = 240
But did'nt work.
How can I acieve this ?
Thanks
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试像这样修改你的绘制方法:
Try modifying your paint method like this: