1
HorizontalFieldManager hfm = new HorizontalFieldManager();
this.add(hfm);


LabelField lblheight = new LabelField("Height");

EditField lField = new EditField() {
    protected void layout(int width, int height) {
        super.layout(width, height);
        this.setExtent(200, this.getHeight());
    }

    public int getPreferredWidth() {
        return 200;
    }
};

Background editFieldBackground = BackgroundFactory
        .createSolidBackground(0X00F7F7FF);
XYEdges edges = new XYEdges(5, 5, 5, 5);
Border border = BorderFactory.createRoundedBorder(edges, 0X00D6DBDE,
        Border.STYLE_FILLED);

Bitmap switchOn = Bitmap.getBitmapResource("switch_left.png");
Bitmap switchOff = Bitmap.getBitmapResource("switch_right.png");
Bitmap switchOnFocus = Bitmap
        .getBitmapResource("switch_left_focus.png");
Bitmap switchOffFocus = Bitmap
        .getBitmapResource("switch_right_focus.png");
SwitchField sw = new SwitchField(switchOn, switchOff, switchOnFocus,
        switchOffFocus, true);
lField.setBackground(editFieldBackground);
lField.setBorder(border);
hfm.add(lblheight);
hfm.add(lField);
hfm.add(sw);

我使用上面的代码在一个水平字段管理器中设置 3 个组件,但我的问题是我在这里设置了 edittext 的宽度。

那么,是否有任何其他选项可以在所有设备上以正确的方式显示 3 个组件,而无需调整编辑文本的宽度?

4

0 回答 0