【发布时间】: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