Android 屏幕尺寸不会像通常那样拉伸以适合屏幕

Android 屏幕尺寸不会像通常那样拉伸以适合屏幕,android,screen,libgdx,Android,Screen,Libgdx,我正在使用box2D渲染查看我的图形(我尝试过使用纹理,得到了完全相同的结果),我的渲染代码如下所示: public void render() { long startTime = System.nanoTime(); world.step(Gdx.app.getGraphics().getDeltaTime(), 3, 3); float updateTime = (System.nanoTime() - startTime) / 1000000000.0f;

我正在使用box2D渲染查看我的图形(我尝试过使用纹理,得到了完全相同的结果),我的渲染代码如下所示:

public void render()
{

    long startTime = System.nanoTime();
    world.step(Gdx.app.getGraphics().getDeltaTime(), 3, 3);
    float updateTime = (System.nanoTime() - startTime) / 1000000000.0f;
    startTime = System.nanoTime();
    float renderTime = (System.nanoTime() - startTime) / 1000000000.0f;

    GL10 gl = Gdx.app.getGraphics().getGL10();
    camera.update();
    camera.apply(gl);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    batch.setProjectionMatrix(camera.combined);

    renderer.render(world, camera.combined);

    batch.begin();


    font.setScale(0.020f);
    font.draw(batch, "fps:" + Gdx.graphics.getFramesPerSecond() + ", update: " + updateTime + ", render: " + renderTime, 0,
        20);
    batch.end();


}
它在桌面版上工作得非常好,并且可以正常显示。

然而,当我在手机上启动它时,我得到了这个,这不是我想要的:

正如你所看到的,它被挤压成只占据屏幕的顶部

libgdx中是否有bug,或者我是否遗漏了什么

编辑:完成创建代码:

Vector2 pouchPos = new Vector2(0, -12);
    slingshotListener = new SlingshotListener(pouchPos);

    batch = new SpriteBatch();
    camera = new OrthographicCamera(32, 48);
    Gdx.input.setInputProcessor(slingshotListener);

    font = new BitmapFont();
    renderer = new Box2DDebugRenderer();
    world = new World(new Vector2(0, -10), true);

    BodyDef bd = new BodyDef();
    ground = world.createBody(bd);

    EdgeShape shape = new EdgeShape();
    shape.set(new Vector2(-16, -20), new Vector2(16, -20));

    FixtureDef fd = new FixtureDef();
    fd.shape = shape;
    ground.createFixture(fd);

    shape.dispose();

    Misc.createLine(new Vector2(-3, -16), pouchPos, camera, world).setSensor(true);
    Misc.createLine(new Vector2(3, -16), pouchPos, camera, world).setSensor(true);

    pic = new Texture(Gdx.files.internal("pong/ball.png"));

我把它放在AndroidManifest.xml中,它似乎解决了这个问题:

<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="13" />


如何设置视口和摄影机位置?我认为是显示分辨率的差异导致了两者的显示方式不同。这个问题的答案可能会有所帮助:即使您的设置有点不同(看起来您在libgdx中没有使用2D场景图)。主要的一点是,您需要将视口居中并定位摄影机。在处理
resize()
时应执行这些操作。您应在该XML前面添加4个空格,使其显示在答案中。此外,您知道更改预期版本会改变显示的原因吗?与MiniDKVersion 3有关,仅支持高达480x320的分辨率,使我的游戏在分辨率大于480x320的手机上以某种兼容模式运行。