iulyus01
iulyus01

Reputation: 37

Libgdx cell horizontal align

I have a table like this:

http://prntscr.com/fkvzt7

All what I want is to align easy, medium and hard texts in the middle of the cell, at least horizontally. I searched a lot on how to do this, but I didn't find anything useful... My code for the table is this:

table.setBounds(0, 0, Info.Width, Info.Height);
table.row();
table.add(label).expandX().colspan(3);
table.row().padTop(20).width(Info.Width);
table.add(easyText).width(Info.Width / 3).expandX();
table.add(mediumText).width(Info.Width / 3).expandX();
table.add(hardText).width(Info.Width / 3).expandX();
table.row().padTop(10);
table.add(easyHighscoreLabel).width(Info.Width / 3);
table.add(mediumHighscoreLabel).width(Info.Width / 3);
table.add(hardHighscoreLabel).width(Info.Width / 3);
table.row().padTop(50);
table.add(backButton).expandX().colspan(3);

Info.Width, Info.Height are the width and the height of the app. label is the title: "HIGHSCORES". easyText, mediumText, hardText are the texts I want to align. easyHighscoreLabel, mediumHighscoreLabel, hardHighscoreLabel, are the numbers below the text. And backButton is "Back" from bottom.

Upvotes: 0

Views: 1165

Answers (1)

AAryan
AAryan

Reputation: 20140

Use setAlignment (int alignment) on your label by default it is left center.

easyText.setAlignment(Align.center);
mediumText.setAlignment(Align.center);
hardText.setAlignment(Align.center);

This will align all the text by center within the label.

Upvotes: 1

Related Questions