我希望在我的 libGDX 应用程序中显示带有图像按钮的列表。 这个想法是图像的大小可以说是 400x100 像素。 我需要列表能够显示拉伸(stretch)到屏幕宽度的图像 - 图像的高度应该调整大小以保持纵横比。
但每次我尝试这样做时,图像都无法正确调整大小。 当图像小于屏幕宽度或填充不良或宽高比错误时,图像不会被拉伸(stretch)。
你能建议一个方法来做到这一点,我正在努力寻找任何解决方案.. actor 必须是 Button a button..(需要“选中”/选中的功能)
我试着做这样的事情:
Table table = new Table();
table.setFillParent(true);
Texture t1 = ... snip ...
Texture t2 = ... snip ...
ImageButton i1 = new ImageButton( new TextureRegionDrawable(new TextureRegion(t1));
ImageButton i2 = new ImageButton( new TextureRegionDrawable(new TextureRegion(t2));
i1.getImageCell().expandX().fillX();
i2.getImageCell().expandX().fillX();
table.add(i1).expandX().fillX();
table.row();
table.add(i2).expandX().fillX();
getStage().add(table);
最佳答案
这对我有用:
imageButton.setBounds(x, y, 128, 128);
imageButton.getImageCell().expand().fill();
关于resize - libGDX 自动调整图像按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22788726/