【问题标题】:Center ButtonField in a FieldManagerFieldManager 中的中心 ButtonField
【发布时间】:2011-12-28 12:05:45
【问题描述】:


我想在 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);

【问题讨论】:

    标签: blackberry blackberry-jde


    【解决方案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);
    

    此代码将运行良好.. 我已经测试过了...

    【讨论】:

    • 谢谢,我在 Horizo​​ntalfieldmanager 中添加了 USE_ALL_WIDTH 然后修改了 setMargin 方法使其工作,再次感谢
    【解决方案2】:

    试试这段代码

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

    【讨论】:

    • 我已经尝试删除 USE_ALL_WIDTH,但是当我这样做时,Horizo​​ntalFieldManager 的背景仅在按钮附近为黑色,屏幕的其余部分保持白色
    【解决方案3】:
    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());
        }
    };
    

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

    【讨论】:

      猜你喜欢
      • 2012-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-14
      • 1970-01-01
      • 1970-01-01
      • 2012-09-08
      相关资源
      最近更新 更多