I have a Table and a Label with wrapped text. I want to display some images in-line with the text. For example:

This is an image -IMAGE_HERE-, and now some more text showing, yet, another image -IMAGE_HERE-.

I tried using one Label containing all the text and spaces for the images, then draw the sprites. However, I can't get the locations I should draw the sprite in to fill those spaces. I could hard-code the values, but they'll vary per device. I also tried adding multiple labels with images between, but that didn't work out either.

Is there a way of fixing this, say by calculating words' widths? Is it possible to have text with inline images in a Table?

if you are wondering why I'm using a Table: The Label text should fit on screen regardless of device resolution. I've found a Table helps with this: I just set bounds and size and it works.

  • \$\begingroup\$ @Anko Thanks for the edit, I posted this late at night so I couldn't think very well, then I just left it xD \$\endgroup\$ – user959631 Mar 19 '14 at 17:32

Use an Image instance instead of Sprite because Image extends Actor and can be added to a Table as an individual actor.
Then split the content to be displayed on your screen into four pieces: one for the first bit of text, one for the first Image, one for the second bit of text, and the last for the second Image.
Add these actors to different cells in the same row in the table:


You can then play with various layout/spacing/sizing effects in the table as you see fit for your case. Just type in "." on the add(actor) method and then hit Ctrl + Space to see what functionality it provides.

You might also want to check out the following link which provides a pretty nice description of the TableLayout: TableLayout.

Hope this helps.

  • \$\begingroup\$ Reason for me using a Sprite is I set a rotation/size which I don't think can be done with an Image, I have actually played around with the methods and looked at various sources on the internet, but I can't seem to get it working the way I want it to. But I have found another solution to this, which I don't particularly like. But works. \$\endgroup\$ – user959631 Mar 18 '14 at 18:04

I couldn't find any help with my issue so I resorted to adding multiple Labels and using the Label's X, Y, width and height to set the position of the Sprite.

I also require an animation which I don't think is possible in a Table, so I will have to just do this.

Thanks for your help.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.