【问题标题】:Blackberry -- Updating screen changes drawing order of manager its field elementsBlackberry -- 更新屏幕更改管理器其字段元素的绘制顺序
【发布时间】:2010-11-04 22:28:52
【问题描述】:

场景
在一个屏幕中,我有 2 个管理器:1)顶部的菜单管理器和 2)具有信息/按钮元素的正文管理器。菜单管理器进行自定义绘图,以便其菜单元素(LabelFields)间隔适当。

核心问题 - 经理和子字段绘图顺序
屏幕画得很好,除非用户执行一个操作(单击一个按钮)导致添加/删除带有正文管理器的元素。一旦从正文中添加/删除字段元素,绘制菜单的顺序就会混淆。

当主体管理器添加或删除一个字段时,菜单管理器开始绘制它的子元素,然后是它自己,而不是菜单管理器先绘制它自己,然后再绘制它的子元素(标签字段)

em>;因此在标签字段的顶部进行绘画,使它们看起来像是消失了。

评论
已经尝试过 invalidate 和其他选项——在从正文中添加/删除字段元素后,我尝试调用 invalidate、invalidateall、updateDisplay...。都没有成功。

删除自定义子布局有效——我可以解决此问题的唯一方法是删除菜单管理器自定义子布局逻辑。不幸的是,菜单系统以传统方式绘制并且没有提供足够的间距。

下面是菜单管理器的子布局代码,我这里有什么遗漏吗?

public void sublayout(int iWidth, int iHeight)
{
    final int iNumFields = getFieldCount();
    int maxHeight = 0;


    final int segmentWidth = iWidth / iNumFields;
    final int segmentWidthHalf = segmentWidth / 2;

    for (int i = 0; i < iNumFields; i++)
    {
        final Item currentField = (Item)this.getField(i);

        // 1. Use index to compute bounds of the field
        final int xSegmentTrueCenter = segmentWidth * i + segmentWidthHalf;

        // 2. center field inbetween bounds using field width (find fill width of text)
        final int xFieldStart = xSegmentTrueCenter - currentField.getFont().getAdvance(currentField.getText())/2;

        // set up position
        setPositionChild(currentField, xFieldStart, getContentTop() + MenuAbstract.PADDING_VERTICAL);

        // allow child to draw itself
        layoutChild(currentField, iWidth, currentField.getHeight());


        // compute max height of the field
        //int fieldheight = currentField.getHeight();
        maxHeight = currentField.getHeight() > maxHeight
            ? currentField.getHeight() + 2 * MenuAbstract.PADDING_VERTICAL
            : maxHeight;
    }
    this.setExtent(iWidth, maxHeight);
}

最后的问题
最终,我想保留菜单管理器的自定义布局,同时允许重绘字段元素。这是我最后的问题:

  1. 你以前有过这种情况吗?

  2. 当向屏幕添加/删除字段元素时,为什么菜单管理器会以错误的顺序开始绘制?

  3. 本机 Manager.sublayout() 是否会做一些我不想维护绘图顺序的事情?

【问题讨论】:

    标签: user-interface layout blackberry repaint


    【解决方案1】:

    我没有看到你描述的行为,但是下面这行有点令人不安:

    // allow child to draw itself
    layoutChild(currentField, iWidth, currentField.getHeight());
    

    getHeight() 不应该返回一个合理的值,直到该字段通过 layoutChild 方法调用了 setExtent。虽然我希望它会在所有情况下都会导致问题 - 不知道为什么这会在第一次出现。在您的逻辑中,我认为您可以安全地在该行中使用 iHeight 而不是 currentField.getHeight() 。该字段只会使自己尽可能大 - 它不会使用所有 iHeight 除非它类似于 VerticalFieldManager

    【讨论】:

    • 我同意 AtariPete 关于 getHeight() 在设置范围之前的有效性。我建议尝试在 layoutChild() 调用中使用 currentField.getPreferredHeight():layoutChild(currentField, iWidth, currentField.getPreferredHeight());
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-18
    相关资源
    最近更新 更多