[LibGDX] TableLayout - Filling a cell with an Image, without stretching it

Hey guys!

Hopefully, there is a solution to this. I can’t imagine there wouldn’t be.

I’m using the scene2d.ui in LibGDX. The Image I’m filling a cell with is the Image widget from scene2d.ui.
I’d like to make the image the biggest it can be in the cell, while keeping proportion. I’m not happy with .width(contant), and .height(constant), because I’d like to support variable screen sizes on android, and the table needs to adjust to each.

So far, I’m calling .expand() on the cell.
When I call .fill() as well, the image is ripped out of proportion - same goes for .fillX() and .fillY().

So, how do you guys do it?

PS.
I’m providing a picture of the situation. (It’s the heart image)

Also, here is the code responsible for that specific cell.

mazePreview = new Image(this.getAssetManager().get("res/heart.png", Texture.class));
table.add(mazePreview).expand();

mazePreview.setScaling(Scaling.fit); // Default is Scaling.stretch, as you found.
table.add(mazePreview).expand().fill();

There is also a Scaling constructor parameter, if you prefer.

Scaling is neat, it just does the math to fit one rectangle in another, in various ways.

Awesome! Thank you very much!