简体   繁体   English

在 libgdx 中调整表格单元格中的图像大小

[英]resize image in table cell in libgdx

When I put my image into my table cell, it always fill the cell.当我将图像放入表格单元格时,它总是填充单元格。 Even though I set the image size with different values.即使我使用不同的值设置了图像大小。 Here's my code:这是我的代码:

    ...
    myTable.row();
    Image imageActor = new Image(skin.getDrawable("bowArrowSq3"));
    imageActor.setSize(300, 100);
    myTable.add(imageActor).width(300).height(200)
            .pad(padding);
    myTable.row();
    ....

In the above code, imageActor's height is always 200 as set by parent cell.在上面的代码中,imageActor 的高度始终为父单元格设置的 200。 How do I size my image and place it somewhere in my cell?如何调整图像大小并将其放置在单元格中的某个位置?

You could add a container:您可以添加一个容器:

myTable.row();
Image imageActor = new Image(skin.getDrawable("bowArrowSq3"));
imageActor.setSize(300, 100);
Table container = new Table();
container.addActor(imageActor);
myTable.add(container).width(300).height(200).pad(padding);
myTable.row();

Container will fit the cell but you should be able to place the image where you want within it.容器将适合单元格,但您应该能够将图像放置在其中所需的位置。

In my case (size of actor needs to be same as cell), the problem was the image was scaled (default).在我的情况下(演员的大小需要与单元格相同),问题是图像被缩放(默认)。 After setting scale type it worked as expected.设置比例类型后,它按预期工作。

imageActor.setScaling(Scaling.fit); myTable.add(imageActor).width(300).height(200).pad(padding); //image is not streched

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

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