【发布时间】:2018-08-31 17:21:09
【问题描述】:
我已经创建了一个包含按钮的带有 scened2d 的表,但是这些按钮有很多问题。
第一个问题是缩放,每当我尝试设置按钮的高度和高度时,都会出现问题 当我设置它时:
table.add(btn).with(100).height(30);
或
btnStyle.up.setMinWidth(80);
btnStyle.up.setMinHeight(40);
btnStyle.down.setMinWidth(80);
btnStyle.down.setMinHeight(40);
按钮已正确缩放,但背景表现得很奇怪
但是如果我不设置它们的高度和高度,它们的背景是正常的,但是按钮太大了
第二个问题,按钮不能“工作”,因为我不能点击(没有改变) 这是代码
// style
final Skin skin = new Skin(Gdx.files.internal("skin/glassy-ui.json"));
final BitmapFont font = skin.getFont("font");
final TextButton.TextButtonStyle btnStyle = new TextButton.TextButtonStyle();
btnStyle.font = font;
btnStyle.up = skin.getDrawable("button");
btnStyle.down = skin.getDrawable("button-down");
btnStyle.up.setMinWidth(80);
btnStyle.up.setMinHeight(40);
btnStyle.down.setMinWidth(80);
btnStyle.down.setMinHeight(40);
// buttons
Textbutton btn = new TextButton("some text", btnStyle);
我怎样才能正确缩放我的按钮,什么可能导致按钮停止工作?
(已经有一个关于按钮缩放的问题,但没有太大帮助)
【问题讨论】:
-
不要设置 minWidth 和 height。设置 prefWidth 和 height。您正在使用的那些暗示着可绘制对象的绘制不可能小于您提供的尺寸,这可能会搞砸它。它没有很好的记录。
-
按钮上的 setHeight 使它看起来像我提供的屏幕截图,我在任何地方都找不到 setPrefWidth
-
增加
stage.camera的视口