Is there any way to append a blank stringItem in form? I want to show a gauge in a form but it should be center aligned. There is no way to do this I think unless there are a few items before the gauge. So I was thinking to add a few null stringItems but they dont work. This is my code so far.

loadingDialog = new javax.microedition.lcdui.Form("Please Wait");
        Gauge gau = new Gauge("\nPlease wait.", false, Gauge.INDEFINITE,
                Gauge.CONTINUOUS_RUNNING);
        gau.setPreferredSize(230,80);
        gau.setLayout(Item.LAYOUT_BOTTOM);
        //Displayable SizeCanvas = new MyCanvas();
        StringItem st = new StringItem(" ", " ");
        loadingDialog.append(st);
        loadingDialog.append(gau);
        parentMidlet.displays.setCurrent(loadingDialog);
有帮助吗?

解决方案

There is a special layout directive to center an item, called unsurprisingly, LAYOUT_CENTER

Using the code snippet you gave, this directive could be set like,

gau.setLayout(Item.LAYOUT_BOTTOM | Item.LAYOUT_CENTER);

Or, if you want to have it set in a separate statement,

gau.setLayout(gau.getLayout() | Item.LAYOUT_CENTER);

If your device is MIDP 2.0, this directive is not mandated to follow (although one can expect a device of reasonable quality to support it). In MIDP 2.1 device, it is mandated to be supported by explicit requirement in the specification.


By the way, for more advanced purposes of item alignment, there is a dedicated lcdui object called Spacer:

A blank, non-interactive item that has a settable minimum size. The minimum width is useful for allocating flexible amounts of space between Items within the same row of a Form. The minimum height is useful for enforcing a particular minimum height of a row. The application can set the minimum width or height to any non-negative value. The implementation may enforce implementation-defined maximum values for the minimum width and height...

...Spacer's primary purpose is to position other item...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top