EditField
デフォルトでは、レイアウト中に渡された使用可能なすべての幅を消費します。結果として、2 番目の EditField に残された使用可能な幅は 0 になります。それらを並べてレイアウトするには、次のいずれかを行う必要があります。
- 親の
sublayout()
メソッド (またはlayout()
の場合Manager
) で手動でレイアウトします。
- EditField の
layout()
メソッドをオーバーライドし、すべての幅ではなく固定幅を消費するようにします。
オプション 1 :
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);
オプション 2:
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) {
// Limit the width of the edit field to be the half of the available width
protected void layout(int width, int height) {
super.layout(width/2, height);
}
};
txtRadiusFeet.setBorder(BorderFactory.createRoundedBorder(new XYEdges()));
EditField txtRadiusInches = new EditField("Inches: ", "", 2, BasicEditField.FILTER_NUMERIC);
txtRadiusInches.setBorder(BorderFactory.createRoundedBorder(new XYEdges()));
HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_WIDTH);
hfm.add(txtRadiusFeet);
hfm.add(txtRadiusInches);
hManagerBinHeight.add(lblRadiusOfBin);
hManagerBinHeight.add(hfm);
add(hManagerBinHeight);
結果
