我想在HorizontalFieldManager中居中放置buttonField
我试过这个代码:
HorizontalFieldManager ButM = new HorizontalFieldManager(Field.FIELD_HCENTER|USE_ALL_WIDTH)
{
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(0x00000000);
graphics.clear();
super.paint(graphics);
}
};
ButtonField Order = new ButtonField("Tri",Field.FIELD_HCENTER|ButtonField.CONSUME_CLICK);但是ButtonField没有居中,我是不是做错了什么?
编辑:
我用下面的代码解决了这个问题:
HorizontalFieldManager ButM = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER|USE_ALL_WIDTH)
{
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(0x00000000);
graphics.clear();
super.paint(graphics);
}
};
ButtonField Order = new ButtonField("Tri",DrawStyle.HCENTER|ButtonField.CONSUME_CLICK);
Order.setMargin(0,0,0,(Display.getWidth()/2)-30);发布于 2011-12-29 15:35:42
HorizontalFieldManager ButM = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER)
{
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(0x00000000);
graphics.clear();
super.paint(graphics);
}
};
ButtonField Order = new ButtonField("Tri",DrawStyle.HCENTER|ButtonField.CONSUME_CLICK);
Order.setMargin(0,0,0,(Display.getWidth() - Order.getPreferredWidth())/2 );
ButM.add(Order);这段代码可以正常运行..我已经测试过了..。
发布于 2011-12-28 20:19:03
试试这段代码
HorizontalFieldManager ButM = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER)
{
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(0x00000000);
graphics.clear();
super.paint(graphics);
}
};
ButtonField Order = new ButtonField("Tri",DrawStyle.HCENTER|ButtonField.CONSUME_CLICK);
ButM.add(Order);发布于 2011-12-29 12:41:40
HorizontalFieldManager ButM = new HorizontalFieldManager(USE_ALL_WIDTH)
{
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(0x00000000);
graphics.clear();
super.paint(graphics);
}
public void sublayout(int width,int height)
{
layoutChild(button,preferredWidth,preferredHeight);
setPositionChild(button, (Graphics.getScreenWidth()-button.getWidth())/2, 0);
setExtent(Graphics.getScreenWidth(),this.getHeight());
}
};试试这个..。希望能对你有所帮助
https://stackoverflow.com/questions/8655706
复制相似问题