Manual Positioning

The controls can be added in the container and window and to accomplish this we have some constants defined in the Control class that will aid in the positioning of the controlers

Positioning on screen

To position a controller on the screen, simply use the ADD method

How to add a control on screen
public void initUI() {
   // control, Positioning on the x axis, Positioning on the y axis) 
    add( new Label("Add a label for this screen"), CENTER, CENTER);
}    

The add method has some Overloading

Overloading add
    add(control, x axis, y axis, width, length)
    add(control, x axis, y axis, int width, int length, relativeControl)
    add(control, x axis, y axis) 
    add(control, x axis, y axis, relativeControl)

If no relative control is added in the method add, the relative control will be the last control added on the screen.

How to add a control on screen
add( new Label("Add a label for this screen"), CENTER, CENTER, relativeControl);

Positioning on the X axis

Positioning on the Y axis

Position with DP

You can also position the control using DP. Just use the UnitsConverter.toPixels()

public void initUI() {
        Label lbl1 = new Label("");
        lbl1.setBackColor(Color.RED);

        Label lbl2 = new Label("");
        lbl2.setBackColor(Color.GREEN);
        
        add(lbl1, CENTER, CENTER, WILL_RESIZE , PREFERRED);
        add(lbl2, UnitsConverter.toPixels(DP + 50), UnitsConverter.toPixels(DP + 400), SCREENSIZE, PREFERRED);
}

Control size

To achieve greater precision, it is possible to add and subtract values to the parameters passed in the size of the control

Images

Last updated