- Home /
Question by
dandepeched · Aug 26, 2017 at 04:35 AM ·
uitextlayout
Cannot get text+image always centered
Hi,
I am trying to resolve simple task - show coins amount (text) with the coin image next to it. Amount can be changed, so this group should center itself on the screen.
I've nearly got what I want, but it not always centered correctly. When amount grows larger then center shifts to the left, but when amount shrinks - center goes back to normal:
Here is how I set it up: 1. Parent - Horizontal Group 2. Child 1 - Text 3. Child 2 - Image
Parent: Child1: Child 2: http://imgur.com/fiHgSJt
How can I achive my task without this "jumping" text effect? Thanks
horizontal-group.png
(31.2 kB)
coins-text.png
(41.1 kB)
Comment
Best Answer
Answer by dandepeched · Sep 05, 2017 at 11:38 AM
I resolved this problem by rebuilding layout each time when I set new text.
[SerializeField]
RectTransform coinsLayout;
LayoutRebuilder.ForceRebuildLayoutImmediate(coinsLayout);