如何在j2me中防止屏幕旋转?

时间:2012-05-24 05:32:08

标签: java-me rotation

我在j2me编程。 对于支持屏幕旋转的所有手机,如何防止j2me中的屏幕旋转?

感谢。

2 个答案:

答案 0 :(得分:2)

如果使用Canvas绘制屏幕(不是LCDUI,不是LWUIT,不是任何其他框架),您可以实现sizeChanged方法,以便在旋转发生时得到通知。

在这种情况下,您可以将屏幕绘制到图像并使用Sprite旋转它。例如,为了仅支持横向模式,我在构造函数中使用了下面的代码:


    int width = Math.max(super.getWidth(), super.getHeight());
    int height = Math.min(super.getWidth(), super.getHeight());
    // screen and sprite are attributes
    screen = Image.createImage(width, height);
    sprite = new Sprite(screen);
    if (super.getWidth() < super.getHeight()) { // portrait screen
        sprite.setTransform(Sprite.TRANS_ROT90);
        sprite.setPosition(0, 0);
    }

以下方法:


    public void sizeChanged (int w, int h) {
        // lastWidth and lastHeight are attributes
        lastWidth = w;
        lastHeight = h;
        if (sprite == null)  return;
        if (super.getWidth() < super.getHeight()) { // portrait screen
            sprite.setTransform(Sprite.TRANS_ROT90);
        } else {
            sprite.setTransform(Sprite.TRANS_NONE);
        }
        sprite.setPosition(0, 0);
    }

    protected void paint(Graphics g1) {
        if (super.getWidth() != lastWidth
            || super.getHeight() != lastHeight) {
            sizeChanged(super.getWidth(), super.getHeight());
        }
        Graphics g = screen.getGraphics();
        // ... do your drawing on g
        this.sprite.setImage(screen, screen.getWidth(), screen.getHeight());
        sprite.paint(g1);
    }

http://smallandadaptive.blogspot.com.br/2009/08/fullscreen-landscape.htmlhttp://smallandadaptive.blogspot.com.br/2010/03/adapting-to-sizechanged.html以及http://smallandadaptive.blogspot.com.br/2011/04/sizechanged-not-called.html

答案 1 :(得分:1)

添加到清单

对于诺基亚设备: Nokia-MIDlet-App-Orientation:Landscape

对于三星设备: MIDlet-ScreenMode:Landscape