修改股票代码

发布于 2024-10-31 04:14:03 字数 1711 浏览 6 评论 0原文

我尝试修改下面的类,以便滚动文本出现在绘制在屏幕左下角的“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘羡 2024-11-07 04:14:03

尝试像这样修改你的绘制方法:

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 );

}

Try modifying your paint method like this:

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 );

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文