元素在不同屏幕上改变大小

时间:2015-03-28 21:31:38

标签: android libgdx position

我把这个ImageButton放在一个表中,并在舞台中添加为演员。它在我的手机上看起来很棒,但是当我在平板电脑上运行时,按钮太大而且位置不合适。我已经在这个阶段宣布了一个视口(我曾尝试使用不同类型的视口):

stageButton = new Stage(new ExtendViewport(screenWidth, screenHeight));

然后这是调整大小的方法:

public void resize(int width, int height) {



    stageButton.getViewport().update(width, height, true);

    table.setBounds(backButtonW, backButtonH, buttonSizew, buttonSizeH);
    stageText.getViewport().update(width, height, true);
    view.update(width, height);
    camera.position.set(camera.viewportWidth/2, camera.viewportHeight/2, 0);
    //camera.update();
}

我只是设置了这样的大小和位置:

public static  float buttonSizeH = 110;
public static  float buttonSizew = 110;
table.add(btnArrow).pad(30).size(buttonSizew, buttonSizeH);
    table.add(btnFB).size(buttonSizew, buttonSizeH);

    table.setBounds(backButtonW, backButtonH, buttonSizew, buttonSizeH);

如果重要,这就是我用视口设置相机的方式:

camera = new OrthographicCamera();
    view = new StretchViewport(screenWidth, screenHeight,camera);
    view.apply();

    camera.position.set(camera.viewportWidth/2, camera.viewportHeight/2, 0);

0 个答案:

没有答案