有人可以告诉我为什么我不能将2个EditFields与下面的代码并排放置?我可以并排放置3个按钮,但由于某种原因,我无法让EditFields为我工作。任何帮助将不胜感激。
//Bin Height
HorizontalFieldManager hManagerBinHeight = new HorizontalFieldManager(FIELD_BOTTOM);
LabelField lblRadiusOfBin = new LabelField("Radius of Bin: ", LabelField.FIELD_LEFT);
EditField txtRadiusFeet = new EditField("Feet: ", "", 3, BasicEditField.FILTER_NUMERIC);
EditField txtRadiusInches = new EditField("Inches: ", "", 2, BasicEditField.FILTER_NUMERIC);
hManagerBinHeight.add(lblRadiusOfBin);
hManagerBinHeight.add(txtRadiusFeet);
hManagerBinHeight.add(txtRadiusInches);
add(hManagerBinHeight);
答案 0 :(得分:3)
EditField
会消耗布局过程中传递给它们的所有可用宽度。因此,第二个EditField的可用宽度为0.为了并排排列它们,您必须:
sublayout()
方法(或layout()
的{{1}})手动布局。Manager
方法并使其消耗固定宽度而非所有宽度。选项1 :
layout()
选项2:
HorizontalFieldManager hManagerBinHeight = new HorizontalFieldManager(FIELD_BOTTOM);
LabelField lblRadiusOfBin = new LabelField("Radius of Bin: ", LabelField.FIELD_LEFT);
final EditField txtRadiusFeet = new EditField("Feet: ", "", 3, BasicEditField.FILTER_NUMERIC);
txtRadiusFeet.setBorder(BorderFactory.createRoundedBorder(new XYEdges()));
final EditField txtRadiusInches = new EditField("Inches: ", "", 2, BasicEditField.FILTER_NUMERIC);
txtRadiusInches.setBorder(BorderFactory.createRoundedBorder(new XYEdges()));
HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_WIDTH) {
protected void sublayout(int maxWidth, int maxHeight) {
layoutChild(txtRadiusFeet, maxWidth/2, maxHeight);
layoutChild(txtRadiusInches, maxWidth/2, maxHeight);
setPositionChild(txtRadiusFeet, 0, 0);
setPositionChild(txtRadiusInches, txtRadiusFeet.getWidth(), 0);
setExtent(maxWidth, txtRadiusFeet.getHeight());
};
};
hfm.add(txtRadiusFeet);
hfm.add(txtRadiusInches);
hManagerBinHeight.add(lblRadiusOfBin);
hManagerBinHeight.add(hfm);
add(hManagerBinHeight);
结果