0

こんにちは、カスタム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見た目はいいですがBackgroundimagehint問題は、テキストフィールドに何も入力していないときに、無限スクロールとして機能していることです。私はHorizontalfieldBasiceditField に依存する幅を設定しましたが、その幅はデフォルトで無制限に設定されています。

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

エンドレススクロールを防ぐ方法は?

前もって感謝します !!!

4

2 に答える 2

3

ホリゾンタルフィールドマネージャーの仮想幅はどれくらいですか?これはスクロール可能なスペースを指し、幅は画面上の範囲を指します。その中でsetVirtualExtentを呼び出して、Horizo​​ntalFieldManagerを拡張し、sublayoutメソッドをオーバーライドしてみることができます。

于 2011-12-28T17:41:45.220 に答える
2

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.

于 2012-05-22T11:09:35.453 に答える