java - 通过坐标自定义 child (children)在manager中的位置

标签 java android blackberry

如何在不使用 Horizo​​ntalFieldManager 或 VerticalFieldManager 且不使用 setMargin() 的情况下通过自定义位置的坐标将字段放置在管理器中:

 __________________________________
 |manager    T               T     |
 |           | y1            |     |
 |           |               |     |
 |           V               |     |
 |   x1   --------------     |y2   | 
 | <---> |  field 1     |    |     |
 |       |______________|    |     |
 |                           |     |
 |                           V     |
 |        x2        ------------   | 
 |   <---------->  |  field 2   |  |
 |                 |____________|  |
 |                                 |
 |                                 |
 __________________________________

我可以使用类似这样的代码吗:

 public static class MyCustomManager extends Manager {
       public MyCustomManager () {
           super();
        }
       public void paint(Graphics g) {/**my painting*/super.paint(g);}
       protected void sublayout(int width, int height) {
        super.sublayout(PLOT, AUKST);

        setPositionChild(??,??)     //Something like this?
        setPosition(??, ??);        // or this? how?
        setExtent(??, ??);
        }

       }

非常感谢!

最佳答案

尝试这样的事情:

public Manager getCustomManager() {
        Manager myCustomManager = new Manager(Manager.NO_HORIZONTAL_SCROLL|Manager.NO_HORIZONTAL_SCROLLBAR|Manager.NO_VERTICAL_SCROLL|Manager.NO_VERTICAL_SCROLLBAR ) {
            protected void sublayout(int width, int height) {
                //Suppose we have to place two fields in our Manager
                if (getFieldCount() == 2) {
                    int
                    /** width and height values for the two fields */
                    w1, h1 , w2, h2 ,
                    /** position values for the two fields */
                    x1=5, y1=5, x2=10, y2=20;

                    // Get the first field added to the manager
                    Field f1 = getField(0);
                    h1 = f1.getHeight();
                    w1 = f1.getWidth();
                    // set the available width and height for the first field
                    layoutChild(f1, w1, h1);
                    // Set the position of the first field in the manager
                    setPositionChild(f1, x1, y1);

                    // Get the second field added to the manager
                    Field f2 = getField(1);
                    h2 = f2.getHeight();
                    w2 = f2.getWidth();
                    // set the available width and height for the second field
                    layoutChild(f2, w2, h2);
                    // Set the position of the second field in the manager
                    setPositionChild(f2, x2, y2);

                    setExtent(width, height);
                } else {
                    setExtent(0, 0);
                    // or  you can do something else in this case...
                }
            };
        };
        return myCustomManager;
    }

关于java - 通过坐标自定义 child (children)在manager中的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8691505/

相关文章:

java - 有没有一种方法可以让多个线程添加到同一个列表对象?

android - 以编程方式 native 崩溃

android - Android动画有问题吗?

image - 与黑莓捆绑图像

java - Swing中的JLabel调整

java - 如何让 JVM 在多态方法调用中将 scala.Array[T] 识别为 java 数组 T[]?

java - JDBC 中的连接是什么?

c# - Xamarin android数据保存到json文件

blackberry - 多重构建和黑莓应用程序世界

java - 确定年份是否为闰年以及日期在 Blackberry 中是否有效