2012-08-15 100 views
2

嗨,我已經通過此鏈接水平實現了滾動文本LabelField Marquee。但是我有一個問題,文本滾動的不錯,但是它被覆蓋在已添加的原始文本上。可以有人知道如何解決這個問題嗎?我也嘗試刷新視圖invalidate()但沒用。我添加了我正面臨的問題的屏幕截圖。TextField橫向滾動

任何幫助將是可觀的。

謝謝。

enter image description here

回答

2

我會建議你改變paint方法來下一個:

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

+0

thankx @ Eugen.Thankx很多人:) ..它是我的錯誤,我在我的paint方法中調用了super.paint()。 – AkashG 2012-08-20 04:36:05

+0

它工作很好,但它顯示從中間到左側的測試,我想這樣做,文本應該從右向左移動甚至文本是小或大。我可以如何處理這段代碼,你能幫助我嗎? – Hasmukh 2012-11-09 11:13:45

+0

查看源代碼 - 將不同的字體設置爲標籤字段,而不是從0位置開始,並在每個滴答聲右移4個符號,先用text.length()開始並向左移動4個符號(將+操作改爲減號) 。如果您仍然有問題 - 請創建新主題 – 2012-11-09 12:28:17

1

我改寫(以更簡單的方式),你鏈接的答案。它工作正常。

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 

    } 

} 
+0

它不工作..仍然是同樣的問題:( – AkashG 2012-08-16 13:28:18

+0

今天早上我再次嘗試你說的方式,但結果是一樣的..它連續移動,但也覆蓋了文本...請讓我擺脫這個 – AkashG 2012-08-17 05:01:02

+0

我在8520模擬器上使用JRE 5.0.0 Java Plugin for Eclipse 1.3.0檢查你的配置 – rosco 2012-08-17 06:58:51