尝试使用setMargin(5,5,5,5) 而不是setPadding(5,5,5,5)。
Field#setMargin()
边距是在边界之后的字段之外的区域。由于这些重叠,因此应由经理正确分配利润。
Field#setPadding()
内边距是字段中内容和边框之间的区域。
Field#SetBorder()
边框是字段内填充外边距之前的区域。
更新:
你是对的,仅用setMargin() 替换setPadding(),并没有产生预期的结果。原因是您使用的Border,更准确地说是它的粗细(10)和样式(STYLE_SOLID)。将边框厚度减小到 3 并将其样式更改为 STYLE_FILLED。
经过上述改动
现在是代码 sn-p:
public class PlayingWithBorders extends MainScreen {
public PlayingWithBorders() {
super(NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL | USE_ALL_HEIGHT | USE_ALL_WIDTH);
VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_HEIGHT | USE_ALL_WIDTH);
vfm.setBackground(BackgroundFactory.createSolidBackground(Color.CYAN));
BasicEditField emailField = new BasicEditField();
emailField.setLabel("Email: ");
emailField.setPadding(5, 5, 5, 5);
emailField.setMargin(5, 5, 5, 5);
emailField.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x0083B0D7, Border.STYLE_FILLED));
emailField.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
BasicEditField passwordField = new BasicEditField();
passwordField.setLabel("Password: ");
passwordField.setPadding(5, 5, 5, 5);
passwordField.setMargin(5, 5, 5, 5);
passwordField.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x0083B0D7, Border.STYLE_FILLED));
passwordField.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
vfm.add(emailField);
vfm.add(passwordField);
add(vfm);
}