FieldManager中的中心ButtonField

时间:2011-12-28 12:05:45

标签: blackberry blackberry-jde


我想在Horizo​​ntalFieldManager中居中一个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);

3 个答案:

答案 0 :(得分:1)

试试这段代码

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);

答案 1 :(得分:1)

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);

此代码运行正常.. 我测试过了......

答案 2 :(得分:0)

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());
    }
};

试试这个..希望它能帮到你