布局USE_ALL_HEIGHT风格Manager,而在黑莓覆盖sublayout()(Layout

2019-09-27 23:01发布

我想布局3 VerticalFieldManager与屏幕NO_VERTICAL_SCROLL 。 一位经理应当与TOP,一要对齐底部,最后一个要消耗前两者之间的高度的其余部分。

是否可以无需重写实现sublaout()对任何管理器? 我想达到的结果是:


我layouted这个屏幕下面的代码。 问题是,我是不是能够做到这一点没有覆盖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);
    }
}

Answer 1:

既然你已经使用MainScreen,你有没有尝试过使用的setTitle()和setStatus()的顶部和底部VerticalFieldManager? 我认为这会做你想要什么。

编辑

如果MainScreen过于具体,您可以编写自己的MainManager,它支持相同的布局组件MainScreen - 旗帜,标题,主要内容,地位。 你将不得不虽然编写自己的布局代码,所以你仍然会执行sublayout(),您特别想避免。 有利的一面是,这将是更多的组合性 - 你将不会被覆盖在随机UI组件的ad-hoc方式sublayout()方法。



文章来源: Layout a Manager with USE_ALL_HEIGHT style without overriding sublayout() in BlackBerry