简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM