【问题标题】:TextField horizontal-scrollingTextField 水平滚动
【发布时间】:2012-08-15 06:13:21
【问题描述】:

您好,我已经通过此链接LabelField Marquee 实现了水平滚动文本。但我有一个问题,文本滚动得很好,但它被覆盖在添加的原始文本上。有人知道如何解决这个问题吗?我还尝试通过invalidate() 刷新视图,但没有用。我已经添加了我面临的问题的屏幕截图。

任何帮助都将不胜感激。

谢谢。

【问题讨论】:

    标签: blackberry horizontal-scrolling labelfield


    【解决方案1】:

    我建议你将绘画方法更改为下一个:

     public void paint(Graphics graphics) {
        currentText = this.getText();
        if (currentChar < currentText.length()) {
            currentText = currentText.substring(currentChar);
    
        }
        graphics.drawText(currentText, 0, 0, DrawStyle.ELLIPSIS, 200);
    }
    

    所以不要在您的paint 中调用super.paint()

    【讨论】:

    • thankx @Eugen.Thankx 很多人 :).. 这是我的错误,我在我的绘画方法中调用了 super.paint()。
    • 它工作得很好,但它从中间向左显示测试,我想做喜欢,文本应该从右向左移动,即使文本是小或大。我该如何处理这段代码你能帮我吗?
    • 查看源代码 - 为标签字段设置不同的字体,而不是从 0 位置开始并在每个刻度上向右移动 4 个符号,而是从 text.length() 开始并向左移动 4 个符号(将 + 操作更改为减号)。如果您仍有疑问 - 请创建新主题
    【解决方案2】:

    我已经(以更简单的方式)重写了您链接的答案。它工作正常。

    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.Font;
    import net.rim.device.api.ui.DrawStyle;
    import java.util.Timer;
    import java.util.TimerTask;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.component.LabelField;
    import net.rim.device.api.ui.container.MainScreen;
    
    public class MyScreen extends MainScreen {
    
        public MyScreen() {
    
            super();
    
            MarqueeLabel testLabel2 = new MarqueeLabel("This is a long long " +
                    "long long long long long long long long long long long " +
                    "long long marquee", Field.FOCUSABLE);
            add(testLabel2);
    
        }
    
        class MarqueeLabel extends LabelField {
    
            // Here MarqueeLabel code from your SO linked example
    
        }
    
    }
    

    【讨论】:

    • 我今天早上又按你说的方式再试了一次,但结果是一样的。它不断移动,但也重叠文本...请让我摆脱这个。
    • 我在 8520 模拟器上使用 JRE 5.0.0。 Eclipse 1.3.0 的 Java 插件。检查您的配置。
    • rosco..它在模拟器中运行良好,但在操作系统为 6.0 的设备粗体 9700 中无法运行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-18
    • 1970-01-01
    • 2021-03-23
    相关资源
    最近更新 更多