【问题标题】:Blackberry - set position of field on the screen?黑莓 - 在屏幕上设置字段位置?
【发布时间】:2010-12-18 05:02:58
【问题描述】:

我想将我的字段定位在指定位置。

【问题讨论】:

    标签: user-interface blackberry layout


    【解决方案1】:

    基本上要在经理中设置任何字段位置,您应该:

    1. 覆盖sublayout

    删除了无效的 ImageShack 链接

    扩展管理员代码:

    class CustomVerticalManager extends VerticalFieldManager {
     LabelField mText1 = new LabelField("top");
     LabelField mText2 = new LabelField("bottom");
    
     public CustomVerticalManager() {
      add(mText1);
      add(mText2);
     }
    
     public int getPreferredHeight() {
      return Display.getHeight();
     }
    
     public int getPreferredWidth() {
      return Display.getWidth();
     }
    
     protected void sublayout(int width, int height) {
      width = getPreferredWidth();
      height = getPreferredHeight();
    
      int fieldWidth = mText1.getPreferredWidth();
      int fieldHeight = mText1.getPreferredHeight();
      layoutChild(mText1, fieldWidth, fieldHeight);
      int xPos = (width - fieldWidth) >> 1;
      int yPos = 0;
      setPositionChild(mText1, xPos, yPos);
    
      fieldWidth = mText2.getPreferredWidth();
      fieldHeight = mText2.getPreferredHeight();
      layoutChild(mText2, fieldWidth, fieldHeight);
      xPos = (width - fieldWidth) >> 1;
      yPos = height - fieldHeight;
      setPositionChild(mText2, xPos, yPos);
      setExtent(width, height);
     }
    }
    

    使用示例:

    class Scr extends MainScreen {
     CustomVerticalManager mManager = new CustomVerticalManager();
    
     public Scr() {
      add(mManager);
     }
    }
    

    另见
    Wireless - How to : Create a custom layout manager for a screen
    Blackberry - fields layout animation

    【讨论】:

    • 好答案。 RIM 实际上在 5.0 API 中有一个名为 AbsoluteFieldManager 的新类,但由于某种原因,它从最新的 beta 版本中删除了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多