如何创建三个编辑字段,例如
HorizontalFieldManager hfm_city=new HorizontalFieldManager();
VerticalFieldManager vfm_city = new VerticalFieldManager();
vfm_city.setBorder(
BorderFactory.createBitmapBorder(
new XYEdges(12,12,12,12), borderBitmap
)
);
vfm_city.setMargin(0, 200, 0, 0);
final EditField city = new EditField("", "", 30, BasicEditField.FILTER_DEFAULT){
String emptyString = "City";
protected void paintBackground(Graphics g) {
g.setBackgroundColor(0xFFFFFF);
g.clear();
}
protected void paint(Graphics g) {
int oldColor = g.getColor();
try {
g.setColor(0x000000);
test = super.getText();
if ( test == null || test.length() < 1 ) {
//g.setColor(Config.hint_colour);
g.drawText(emptyString, 0, 0);
}
super.paint(g);
} finally {
g.setColor(oldColor);
}
}
};
vfm_city.add(city);
VerticalFieldManager vfm_state = new VerticalFieldManager();
vfm_state.setBorder(
BorderFactory.createBitmapBorder(
new XYEdges(12,12,12,12), borderBitmap
)
);
vfm_state.setMargin(0, 0, 0, 0);
final EditField state = new EditField("", "", 30, BasicEditField.FILTER_DEFAULT){
String emptyString = "State";
protected void paintBackground(Graphics g) {
g.setBackgroundColor(0xFFFFFF);
g.clear();
}
protected void paint(Graphics g) {
int oldColor = g.getColor();
try {
g.setColor(0x000000);
test = super.getText();
if ( test == null || test.length() < 1 ) {
//g.setColor(Config.hint_colour);
g.drawText(emptyString, 0, 0);
}
super.paint(g);
} finally {
g.setColor(oldColor);
}
}
};
vfm_state.add(state);
VerticalFieldManager vfm_zip = new VerticalFieldManager();
vfm_zip.setBorder(
BorderFactory.createBitmapBorder(
new XYEdges(12,12,12,12), borderBitmap
)
);
vfm_zip.setMargin(0, 0, 0, 0);
final EditField zip = new EditField("", "", 30, BasicEditField.FILTER_DEFAULT){
String emptyString = "Zip";
protected void paintBackground(Graphics g) {
g.setBackgroundColor(0xFFFFFF);
g.clear();
}
protected void paint(Graphics g) {
int oldColor = g.getColor();
try {
g.setColor(0x000000);
test = super.getText();
if ( test == null || test.length() < 1 ) {
//g.setColor(Config.hint_colour);
g.drawText(emptyString, 0, 0);
}
super.paint(g);
} finally {
g.setColor(oldColor);
}
}
};
vfm_zip.add(zip);
hfm_city.add(vfm_city);
hfm_city.add(vfm_state);
hfm_city.add(vfm_zip);
答案 0 :(得分:1)
你正在以正确的方式前进。但你必须给出具体的宽度和宽度。高度为VerticalFieldManager
,否则默认为全宽。
VerticalFieldManager vfm_city = new VerticalFieldManager() {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getwidth()/3,30);
setExtent(Display.getwidth()/3,30);
}
};
在你所在的国家和地区做这件事。城市vfm
并添加hfm
并尝试。
答案 1 :(得分:0)
检查我的答案
{
Border bdr = BorderFactory.createRoundedBorder(new XYEdges(4, 4, 4, 4),Border.STYLE_SOLID);
VerticalFieldManager vert=new VerticalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(),Display.getHeight());
setExtent(Display.getWidth(),Display.getHeight());
}
};
HorizontalFieldManager hr=new HorizontalFieldManager(USE_ALL_HEIGHT)
{
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(),50);
setExtent(Display.getWidth(),50);
}
};
hr.setBackground(BackgroundFactory.createSolidBackground(Color.GREEN));
EditField e1=new EditField(Field.FOCUSABLE|Field.FIELD_VCENTER){
protected void layout(int width, int height) {
super.layout(100,30);
setExtent(100,30);
}
};
EditField e2=new EditField(Field.FOCUSABLE|Field.FIELD_VCENTER){
protected void layout(int width, int height) {
super.layout(60,30);
setExtent(60,30);
}
};
EditField e3=new EditField(Field.FOCUSABLE|Field.FIELD_VCENTER){
protected void layout(int width, int height) {
super.layout(60,30);
setExtent(60,30);
}
};
e1.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
e2.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
e3.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
e1.setPadding(0, 0, 0, 10);
e2.setPadding(0, 0, 0, 20);
e3.setPadding(0, 0, 0, 10);
e1.setBorder(bdr);
e2.setBorder(bdr);
e3.setBorder(bdr);
hr.add(e1);
hr.add(e2);
hr.add(e3);
vert.add(hr);
add(vert);
}