简体   繁体   English

停止libgdx TextButton根据文本改变大小

[英]Stop the libgdx TextButton from changing size depending on text

I am using a textbutton that changes its text from OFF to ON when you click on it. 我正在使用一个文本按钮,当您单击它时将其文本从OFF更改为ON。 But once it does that the size is completely different. 但一旦它这样做,大小就完全不同了。 Is there a way to make the button keep its current size? 有没有办法让按钮保持当前的大小? I've tried setScale and setSize of the button but it does not seem to do anything. 我已经尝试了按钮的setScale和setSize,但似乎没有做任何事情。 I am using the button in a table if that is relevant. 如果相关,我正在使用表格中的按钮。

If you are using the table, you should change the size of the cell instead. 如果您正在使用该表,则应改为更改cell的大小。

For example, lets imagine that your code was: 例如,假设您的代码是:

TextButton btn = new TextButton(...);
btn.setSize(100, 100);
table.add(btn);

You should define it like this instead: 你应该这样定义它:

TextButton btn = new TextButton(...);
table.add(btn).size(100, 100); // <-- resize cell, not button

Please refer this document for more information. 有关更多信息,请参阅文档。

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

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