简体   繁体   English

如何禁用BasicEditField中的无限滚动

[英]how to disable endless scroll in BasicEditField

HI all i have implement Custom BasicEditField to set hint and to input long text . 大家好,我已经实现了Custom BasicEditField来设置提示并输入长文本。

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. 有一个HorizontalFieldManager可以滚动文本。

hfm_searchBox = new HorizontalFieldManager(Manager.HORIZONTAL_SCROLL) ;

There is one Basiceditfield to input text . 有一个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);
                }

            }};

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 . BasicEditField看起来很适合Backgroundimagehint但是问题是,当我在文本字段中没有输入任何内容时,它就像无休止的滚动一样工作。 i have set Horizontalfield width depend on BasiceditField but its width by default set to unlimited . 我已经设置了Horizontalfield宽度取决于BasiceditField,但是默认情况下它的宽度设置为unlimited。

hfm_searchBox.add(txtSearch);
vfm_searchBox.add(hfm_searchBox);

how to prevent endless scroll ? 如何防止滚动不休?

Thanks in Advance !!! 提前致谢 !!!

What is the HorizontalFieldManager's virtual width ? 什么是Horizo​​ntalFieldManager的虚拟宽度 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. 您可以尝试扩展Horizo​​ntalFieldManager并覆盖sublayout方法,在其中调用setVirtualExtent

As Tamar said, the Field's Virtual Width is the key concept to keep track of. 如Tamar所说,“字段的虚拟宽度”是要跟踪的关键概念。

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. 通过动态调用setVirtualExtent() ,您始终可以获得足够的滚动,但滚动不会太多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM