简体   繁体   English

Libgdx单元格水平对齐

[英]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. Info.Width,Info.Height是应用程序的宽度和高度。 label is the title: "HIGHSCORES". 标签是标题:“ HIGHSCORES”。 easyText, mediumText, hardText are the texts I want to align. easyText,mediumText,hardText是我要对齐的文本。 easyHighscoreLabel, mediumHighscoreLabel, hardHighscoreLabel, are the numbers below the text. easyHighscoreLabel,mediumHighscoreLabel,hardHighscoreLabel是文本下方的数字。 And backButton is "Back" from bottom. backButton从底部开始是“ Back”。

Use setAlignment (int alignment) on your label by default it is left center. 默认情况下在标签上使用setAlignment (int alignment) ,该标签位于左侧中心。

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

This will align all the text by center within the label. 这将使所有文本在标签内居中对齐。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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