TextField horizontal-scrolling
-
26-06-2021 - |
Pergunta
Hi i have implemented scrolling text horizontally through this link LabelField Marquee. But i have one problem,the text is scrolling quite good but its been over-written on the original text which was added.Can anyone have any idea how to cope from this problem? I also tried to refresh the view by invalidate()
but of no use. i have added the screenshot of the problem which i am facing.
Any help would be appreciable.
Thank you.
Solução
I would suggest you to change paint method to next:
public void paint(Graphics graphics) {
currentText = this.getText();
if (currentChar < currentText.length()) {
currentText = currentText.substring(currentChar);
}
graphics.drawText(currentText, 0, 0, DrawStyle.ELLIPSIS, 200);
}
So don't call super.paint()
in your paint
.
Outras dicas
I've rewritten (in a more simple way) the answer you linked. It works fine.
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
}
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow