如何将表中的按钮设置为相同的大小?

时间:2014-09-08 04:56:18

标签: libgdx

我试图通过将主菜单按钮设置为相同的尺寸来使UI更具吸引力。

所以" Play"按钮有点大于" Quit"按钮,我试过了:

    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/myfont.ttf"));
    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = 22;
    mButtonSpacefont = generator.generateFont(parameter);
    generator.dispose();

    // Table for Buttons
    Table table=new Table();
    table.setSize(800, 480);

    // Button Skin
    Skin skin = new Skin();
    TextureAtlas buttonAtlas = new TextureAtlas(Gdx.files.internal("gfx/buttons.pack"));
    skin.addRegions(buttonAtlas);

    // BUTTON PLAY
    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.font = mButtonSpacefont;
    textButtonStyle.up = skin.getDrawable("button_top");
    textButtonStyle.down = skin.getDrawable("button_bottom");
    final TextButton buttonPlay = new TextButton("Play", textButtonStyle);

    table.add(buttonPlay);
    table.row();

    // BUTTON QUIT
    final TextButton buttonQuit = new TextButton("Quit", textButtonStyle);
    buttonQuit.setWidth(buttonPlay.getWidth());// make the Quit button same size as Play button
    table.add(buttonQuit).padTop(50);
    table.row();

然而,这不起作用!退出按钮仍然小于播放按钮

我做错了什么?

1 个答案:

答案 0 :(得分:3)

要调整所有按钮的大小,您可以使用Cell类中的width方法,例如:

table.add(buttonPlay).width(100);
table.row();
table.add(buttonQuit).width(100);

那么你的按钮最终应该具有相同的宽度。

相关问题