Java libGDX文本按钮图像大小调整
在libGDX中,我有一个TextButtonStyle,定义如下:Java libGDX文本按钮图像大小调整,java,user-interface,libgdx,scene2d,Java,User Interface,Libgdx,Scene2d,在libGDX中,我有一个TextButtonStyle,定义如下: TextButtonStyle style = new TextButtonStyle(); style.font = header; style.up = Resources.guiSkin.getDrawable("buttonUp"); style.down = Resources.guiSkin.getDrawable("buttonDown"); TextButton textButton = new TextBu
TextButtonStyle style = new TextButtonStyle();
style.font = header;
style.up = Resources.guiSkin.getDrawable("buttonUp");
style.down = Resources.guiSkin.getDrawable("buttonDown");
TextButton textButton = new TextButton("text",style);
table.add(playButton);
我的文本按钮定义如下:
TextButtonStyle style = new TextButtonStyle();
style.font = header;
style.up = Resources.guiSkin.getDrawable("buttonUp");
style.down = Resources.guiSkin.getDrawable("buttonDown");
TextButton textButton = new TextButton("text",style);
table.add(playButton);
我将TextButton添加到如下表中:
TextButtonStyle style = new TextButtonStyle();
style.font = header;
style.up = Resources.guiSkin.getDrawable("buttonUp");
style.down = Resources.guiSkin.getDrawable("buttonDown");
TextButton textButton = new TextButton("text",style);
table.add(playButton);
该表被配置为:(我已经测试了使用和不使用此配置,没有任何更改)
我遇到的问题是TextButtonStyle的纹理style.up和style.down根据按钮的文本调整大小。例如,如果我将“t”写为文本,则style.up和style.down纹理将调整自身大小以仅围绕“t”,而不是保持其原始图像大小
在此图像中,不同长度的文本显示不同大小的按钮,尽管它们都是相同的纹理。此外,正如您所看到的,文本的结尾在按钮内部并不适合所需,因为文本从一端延伸到另一端,从开头开始,在结尾结束,而实际上我希望它从开头之后开始,在结尾之前结束。此外,文本位于图像的底部,看起来很尴尬。总的来说,整个事情看起来很尴尬,我想知道是否有办法解决这个问题
我的想法是,因为我使用一个非常小的图像作为按钮纹理(类似于34x11像素),所以按钮总是调整图像的大小。如果图像大于容纳文本所需的大小,则不会调整大小。然而,我使用的是一个像素主题的按钮,最简单的方法是使用一个小图像,那么有没有办法绕过这个调整大小的方法呢
非常感谢您的帮助。请尝试设置表格单元格的宽度:
table.add(playButton).width(100);
而不是:
table.add(playButton);
这应该可以解决背景图像的宽度问题。您是否已经尝试将宽度属性添加到按钮?@donfuxx Actor.setWidth()方法似乎没有任何作用我指的是表格的width()方法