如何在 BasicEditField 中禁用无限滚动
大家好,我已经实现了自定义 BasicEditField
来设置提示并输入长文本。
请参阅我的代码
vfm_searchBox = new VerticalFieldManager()
{
//Main.Quicksearchinput is background image for inputtext
public void paint(Graphics g)
{
g.setColor(Color.WHITE);
g.drawBitmap(0,0,Main.Quicksearchinput.getWidth(),Main.Quicksearchinput.getHeight(),Main.Quicksearchinput,0,0);
super.paint(g);
}}
有一个 HorizontalFieldManager
来滚动文本。
hfm_searchBox = new HorizontalFieldManager(Manager.HORIZONTAL_SCROLL) ;
有一个Basiceditfield
用于输入文本。
txtSearch = new BasicEditField(BasicEditField.NO_NEWLINE)
{
public void paint(Graphics g)
{
if(super.getText().length() == 0)
{
g.setColor(Color.GRAY);
g.setFont(g.getFont().derive(Font.PLAIN,18));
g.drawText("Enter Event title or subtitle", 0, 0);
super.paint(g);
}
else
{
g.setColor(Color.BLACK);
super.paint(g);
}
}};
BasicEditField
与 Backgroundimage
和 hint
一起看起来不错,但问题是,当我在文本字段中没有输入任何内容时,它会以无限滚动的方式工作。我已设置 Horizontalfield
宽度取决于 BasiceditField 但其宽度默认设置为 unlimited 。
hfm_searchBox.add(txtSearch);
vfm_searchBox.add(hfm_searchBox);
如何防止无限滚动?
提前致谢 !!!
HI all i have implement Custom BasicEditField
to set hint and to input long text .
please see my code
vfm_searchBox = new VerticalFieldManager()
{
//Main.Quicksearchinput is background image for inputtext
public void paint(Graphics g)
{
g.setColor(Color.WHITE);
g.drawBitmap(0,0,Main.Quicksearchinput.getWidth(),Main.Quicksearchinput.getHeight(),Main.Quicksearchinput,0,0);
super.paint(g);
}}
There is one HorizontalFieldManager
to scroll text.
hfm_searchBox = new HorizontalFieldManager(Manager.HORIZONTAL_SCROLL) ;
There is one Basiceditfield
to input text .
txtSearch = new BasicEditField(BasicEditField.NO_NEWLINE)
{
public void paint(Graphics g)
{
if(super.getText().length() == 0)
{
g.setColor(Color.GRAY);
g.setFont(g.getFont().derive(Font.PLAIN,18));
g.drawText("Enter Event title or subtitle", 0, 0);
super.paint(g);
}
else
{
g.setColor(Color.BLACK);
super.paint(g);
}
}};
The BasicEditField
looks nice with Backgroundimage
and hint
but problem is that when i am nothing input in textfield it is working as endless scroll . i have set Horizontalfield
width depend on BasiceditField but its width by default set to unlimited .
hfm_searchBox.add(txtSearch);
vfm_searchBox.add(hfm_searchBox);
how to prevent endless scroll ?
Thanks in Advance !!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HorizontalFieldManager 的 虚拟宽度?这是指可滚动空间,而宽度是指屏幕上的范围。您可以尝试扩展 HorizontalFieldManager 并覆盖 sublayout 方法,调用 setVirtualExtent 在其中。
What is the HorizontalFieldManager's virtual width? This refers to the scrollable space whereas the width refers to the extent on the screen. You can try extending HorizontalFieldManager and overriding the sublayout method, calling setVirtualExtent in it.
正如 Tamar 所说,字段的虚拟宽度是需要跟踪的关键概念。
您可以在此处查看我对非常类似问题的解决方案。我提供了一个完整的代码示例,它可能与您想要做的事情相去不远。我使用的代码更进一步,动态地将滚动限制为仅滚动到文本当前到达的位置的末尾。如果您不这样做,而只是设置一个恒定的虚拟宽度,那么您可能会让该字段实际上向右滚动太远。通过动态调用
setVirtualExtent()
,您始终会获得足够的滚动,但不会太多。As Tamar said, the Field's Virtual Width is the key concept to keep track of.
You can see my solution to a very similar question here. I provide a full code example that's probably not too far from what you're trying to do. The code I use goes a step further, and dynamically limits scrolling only to the end of where the text currently reaches. If you don't do this, and simply set one constant virtual width, then you can have the field actually scroll too far to the right. By dynamically calling
setVirtualExtent()
, you always get just enough scrolling, but not too much.