【问题标题】:Layout a Manager with USE_ALL_HEIGHT style without overriding sublayout() in BlackBerry在不覆盖 BlackBerry 中的 sublayout() 的情况下,使用 USE_ALL_HEIGHT 样式布局管理器
【发布时间】:2012-03-03 20:59:25
【问题描述】:

我想在带有NO_VERTICAL_SCROLL 的屏幕中布局三个VerticalFieldManager。一位经理应与 TOP 对齐,一位应与 BOTTOM 对齐,最后一位应消耗前两者之间的其余高度。

可以在不覆盖任何经理的sublaout() 的情况下实现吗?我想要达到的结果是:


我用下面的代码布局了这个屏幕。问题是我无法在不覆盖 sublayout() 的情况下做到这一点。

public class LayoutSandboxScreen extends MainScreen {
    public LayoutSandboxScreen() {
        super(NO_VERTICAL_SCROLL);

        VerticalFieldManager vfmTop = new VerticalFieldManager(USE_ALL_WIDTH);
        vfmTop.setBackground(BackgroundFactory.createSolidBackground(Color.GREEN));
        vfmTop.add(new ButtonField("TOP", FIELD_HCENTER));

        final VerticalFieldManager vfmCenter = new VerticalFieldManager(USE_ALL_WIDTH);       
        HorizontalFieldManager hfmCenter = new HorizontalFieldManager(USE_ALL_HEIGHT | FIELD_HCENTER);
        vfmCenter.setBackground(BackgroundFactory.createSolidBackground(Color.RED));
        hfmCenter.add(new ButtonField("CENTER", FIELD_VCENTER));
        vfmCenter.add(hfmCenter);

        final VerticalFieldManager vfmBottom = new VerticalFieldManager(USE_ALL_WIDTH);       
        vfmBottom.setBackground(BackgroundFactory.createSolidBackground(Color.BLUE));
        final ButtonField btn = new ButtonField("BUTTOM", FIELD_HCENTER);        
        vfmBottom.add(btn);

        VerticalFieldManager vfmSecond = new VerticalFieldManager(USE_ALL_HEIGHT) { 
            protected void sublayout(int maxWidth, int maxHeight) {
                setExtent(maxWidth, maxHeight);

                layoutChild(vfmBottom, maxWidth, maxHeight);
                int bottomHeight = vfmBottom.getHeight();

                layoutChild(vfmCenter, maxWidth, maxHeight - bottomHeight);
                setPositionChild(vfmCenter, 0, 0);

                setPositionChild(vfmBottom, 0, maxHeight - bottomHeight);
            }
        };

        vfmSecond.add(vfmBottom);
        vfmSecond.add(vfmCenter);

        add(vfmTop);
        add(vfmSecond);
    }
}

【问题讨论】:

  • 我也想要一个答案。我还有一个带有底部对齐字段和可变高度中间字段的屏幕,并且必须覆盖 sublayout() 才能手动定位它们。
  • @RemyLebeau-TeamB 这正是我所面临的。我正在一个聊天屏幕上工作,其中包含发送/接收的消息管理器和另一个具有增强的 EditField 的管理器,用户在其中写入新消息。两个经理都是高度可变的。
  • @MrVincenzo 在 MainScreen 上使用 setStatus() 非常适合您的文本输入框。

标签: user-interface blackberry java-me


【解决方案1】:

由于您已经在使用 MainScreen,您是否尝试过对顶部和底部的 VerticalFieldManager 使用 setTitle() 和 setStatus()?我认为这会做你想要的。

编辑

如果 MainScreen 过于具体,你可以编写自己的 MainManager,它支持与 MainScreen 相同的布局组件 - 横幅、标题、主要内容、状态。不过,您必须编写自己的布局代码,因此您仍将实现 sublayout(),这是您特别希望避免的。好处是这将更加可组合 - 您不会在随机 UI 组件上以临时方式覆盖 sublayout() 方法。

【讨论】:

  • 这不是我想要的。 setTitle() 和 setStatus() 适用于特定情况。我的问题比较笼统,不受任何情况的约束。
  • 虽然这不是我希望的答案,但它是最接近的答案。谢谢。
猜你喜欢
  • 1970-01-01
  • 2019-07-20
  • 2018-05-05
  • 2013-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-04
  • 2013-02-06
相关资源
最近更新 更多