本文介绍了在BlackBerry中布置具有USE_ALL_HEIGHT样式的管理器而不覆盖sublayout()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在具有NO_VERTICAL_SCROLL的屏幕中布置三个VerticalFieldManager.一位经理应与顶部保持一致,一位经理应与底部保持一致,而最后一位则应消耗前两位之间的其余高度.

I want to layout three VerticalFieldManager in a screen with NO_VERTICAL_SCROLL. One manager should be aligned to TOP, one should be aligned to BOTTOM and the last one should consume the rest of the height between the former two.

是否可以在不覆盖任何Manager的情况下实现sublaout()的目的?我要实现的结果是:

Can it be achieved without overriding sublaout() for any Manager? The result I want to achieve is:


我使用以下代码对屏幕进行了布局.问题是我无法在不覆盖sublayout()的情况下做到这一点.


I layouted this screen with the following code. The problem is that I wasn't able to do it without overriding 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);
    }
}

推荐答案

由于您已经在使用MainScreen,是否尝试过将setTitle()和setStatus()用作顶部和底部的VerticalFieldManager?我想那会做你想要的.

Since you're already using a MainScreen, have you tried using setTitle() and setStatus() for the top and bottom VerticalFieldManager? I think that will do what you want.

修改

如果MainScreen过于具体,则可以编写自己的MainManager,它支持与MainScreen相同的布局组件-标语,标题,主要内容,状态.但是,您将不得不编写自己的布局代码,因此您仍将实现sublayout(),这是您特别想要避免的.有利的一面是,它将更具可组合性-您不会在随机UI组件上临时覆盖sublayout()方法.

If MainScreen is too specific, you can write your own MainManager, which supports the same layout components as MainScreen - banner, title, main content, status. You will have to write your own layout code though, so you'll still be implementing sublayout(), which you specifically wanted to avoid. The plus side is that this will be more composable - you won't be overriding the sublayout() method in an ad-hoc way on random UI components.

这篇关于在BlackBerry中布置具有USE_ALL_HEIGHT样式的管理器而不覆盖sublayout()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:11
查看更多