我试图通过将主菜单按钮设置为相同的大小来使用户界面更具吸引力。
所以“播放”按钮比“退出”按钮大一点,我尝试过:
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();
Run Code Online (Sandbox Code Playgroud)
然而,这不起作用!退出按钮仍然小于播放按钮
我是不是做错了什么?
要调整所有按钮的大小,您可以使用 Cell 类中的 width 方法,例如:
table.add(buttonPlay).width(100);
table.row();
table.add(buttonQuit).width(100);
Run Code Online (Sandbox Code Playgroud)
那么你的按钮最终应该具有相同的宽度。