1
\$\begingroup\$

I'm using LibGDX v1.1.0 and I see that the label of a TextButton is not properly centered. I have the following code:

m_resumeButton = new TextButton("resume", skin);
m_resumeButton.addListener(new ChangeListener() {
    public void changed(ChangeEvent event, Actor actor) {
        m_state = GameState.RUNNING;
        getGame().getWorld().pauseWorld(false);
    }
});

The default TextButtonStyle is defined as:

"com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle": {
    "default": {
        "up": "menu-button", 
        "down": "menu-button-down", 
        "checked": "menu-button-down", 
        "disabled": "menu-button-disabled", 
        "font": "font24", 
        "fontColor": "white"
    }
}

The menu button images are simple 240x48 bitmaps saved as 9-patch images. An image can be found here to illustrate the problem:

https://www.dropbox.com/s/cwuhu5xb9ro5w6m/screenshot001.jpg

Am I doing something wrong? Or is there a problem with the button images I'm using?

\$\endgroup\$
1
  • \$\begingroup\$ Using a non 9-patch image doesn't make a difference. The label is still not centered properly. \$\endgroup\$ Jun 10, 2014 at 11:40

1 Answer 1

3
\$\begingroup\$

To solve the alignment problem of the label text I found some information on the internet (where else?). It is possible to add some additional padding to the label inside the text button:

TextButton button = new TextButton(text, skin, styleId);
button.setSize(width, height);
// Add some padding to the label in the button to shift it up a bit
button.getLabelCell().padBottom(padding);
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .