Layout a Manager with USE_ALL_HEIGHT style without overriding sublayout() in BlackBerry

左心房为你撑大大i 提交于 2019-12-13 17:48:04

问题


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.

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


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);
    }
}

回答1:


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.

Edit

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.



来源:https://stackoverflow.com/questions/9549827/layout-a-manager-with-use-all-height-style-without-overriding-sublayout-in-bla

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!