【问题标题】:BlackBerry Horizontal Scrolling in TreeField or ListFieldBlackBerry 在 TreeField 或 ListField 中的水平滚动
【发布时间】:2010-03-13 04:30:14
【问题描述】:

我正在开发一个应用程序,该应用程序需要大于 TreeField 和 ListField 中的可视屏幕大小的文本。如您所知,TreeField 和 ListField 回调仅支持 graphics.drawText() 方法,所以我不能每行添加一个 Field 的实例。

有没有人可以水平滚动超过可视文本大小的方法?

是否有可以工作的可滚动面板?我知道 NullField(Field.Focusable) 技巧,但这不适用于列表字段。

最后,我知道屏幕类型会有所不同,因为 FullScreen 和 MainScreen 使用 VerticalFieldMangers。所以我目前正在使用 PopupScreen 进行测试。

提前感谢您的宝贵时间。

【问题讨论】:

    标签: blackberry java-me user-interface


    【解决方案1】:

    也许最好将文本分成两行并将行高设置为 2 x 字体高度(+边距)?

    alt text http://img219.imageshack.us/img219/5802/listh.jpg

    class Scr extends MainScreen implements ListFieldCallback {
        int DISPLAY_WIDTH = Display.getWidth();
        Vector mItems = new Vector();   
        ListField mListField = new ListField();
    
        public Scr() {
            mListField.setCallback(this);
            add(mListField);
            mItems.addElement("Lorem ipsum dolor sit amet, ");
            mItems.addElement("Lorem ipsum dolor sit");
            mItems.addElement("Lorem ipsum dolor sit amet, "+
                "consectetuer adipiscing elit");
            mItems.addElement("Lorem ipsum dolor sit amet, "+
                "consectetuer adipiscing elit, sed diam "+
                    "nonummy nibh euismod");
            mItems.addElement("Lorem ipsum dolor sit amet, "+
                "consectetuer adipiscing elit");
            mItems.addElement("Lorem ipsum dolor sit amet, ");
            mListField.setSize(mItems.size());
            mListField.setRowHeight(
                    mListField.getFont().getHeight()*2 + 4);        
        }
    
        public void drawListRow(ListField field, Graphics g, 
            int i, int y, int w) {
            // Draw the text.
            String text = (String) get(field, i);        
            if(g.getFont().getAdvance(text) > w)
            {
                int index = 0;
                while(g.getFont().getAdvance(text.substring(0, index)) < w)
                {
                    index++;
                }
                g.drawText(text.substring(0, index), 0, y, 0, w);
                g.drawText(text.substring(index, text.length()-1), 0, 
                y + g.getFont().getHeight()+ 4, DrawStyle.ELLIPSIS, w);
            }
            else
            {
                g.drawText(text, 0, y, 0, w);
            }
        }       
    
        public Object get(ListField listField, int index) {
            return mItems.elementAt(index);
        }
    
        public int getPreferredWidth(ListField listField) {
            return DISPLAY_WIDTH;
        }
    
        public int indexOfList(ListField listField,
            String prefix, int start) {
            return 0;
        }
    }
    

    【讨论】:

    • 你可能是对的,这似乎不可能有任何其他方式。我在想,如果我可以只将第二行显示在集中的一行上,这将有助于避免屏幕混乱。
    • 好吧,如果你构建一个自定义控件(垂直管理器 + 标签)... ListField 中的行高对于所有行都是相同的((
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-29
    • 1970-01-01
    相关资源
    最近更新 更多