FieldManager 中的中心 ButtonField

发布于 2024-12-23 04:36:27 字数 990 浏览 2 评论 0原文


我想在水平字段管理器中将按钮字段居中
我尝试了该代码:

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

但是按钮字段没有居中,我做错了什么吗?

编辑 :
我使用以下代码解决了这个问题:

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

I wanna center a buttonField in a HorizontalFieldManager
i tried that code :

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

But the ButtonField is not centred, am i doing something wrong ?

EDIT :

I solved this problem by using this code :

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

缪败 2024-12-30 04:36:27
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);

这段代码将运行良好..
我已经测试过...

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

This code will run fine..
I have test it...

倥絔 2024-12-30 04:36:27

试试这段代码

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

Try this bit of code

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);
維他命╮ 2024-12-30 04:36:27
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());
    }
};

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

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

try this.. hope it will help you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文