- Home /
Display width stretched buttons in UI
I want to display button in its full width. Basically I have achieved following by spending time on this.
At present you are clearly seeing gap between buttons. I want to remove these gaps for all aspect ratios. I want each of my button of full width. At present I have added Horizontal Layout Group to parent of these 3 buttons. Each 3 buttons contain following Layout Element script.
Now I am waiting for some clever reply. Please give me some hint in this.
Answer by troien · Apr 08, 2016 at 09:02 AM
Ok.. So to be clear, you want the orange/brown buttons to not have gaps between them?
If so:
Check the 'spacing' of the horizontal layout group (You should set it to 0). This should remove any gaps between the buttons.
Check the 'child force expand' in the horizontal layout group (or check flexible width for all the buttons). This should stretch the buttons to fill the horizontal layout group.
If after step 1 you still have gaps between your buttons, then this is most likely caused by a transparent border around the sprite you used. You could fix that by selecting a sprite without a transparent border or perhaps by setting the spacing to a value lower then 0...
$$anonymous$$ay be Layout Element affect in this!!!
Well, it looks like your settings of the layout group are correct. So the only thing that I believe could be wrong here is the sprite/texture/image you use for the buttons. If this sprite has transparent borders, then when you place them next to each other, these transparent borders will create a gap between your buttons like I said in my answer. Try making a sprite without transparent borders and use that, or set the 'spacing' to a value lower then 0 (how much lower I don't know, that depends on the width of the transparent border)
For this your all opinions are correct. But in my one this mistake exist. Actual parent get scale to fit width but sprite exist in to child object and that was also set with center anchor position. Following image gives you more idea.
So I applied full stretched setting to all child images and problem get solved.
Your answer
![](https://koobas.hobune.stream/wayback/20220612074420im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Subclassing Button, public variable won't show up in the inspector 5 Answers
Unity 5 WebGL Facebook SDK UI Button Sharing not Working 0 Answers
UI cycling through my level select levels 1 Answer
a function is working on editor but not working on android divice 1 Answer
Change scene and play it by clicking UI Button? Scene does just load but not start playmode? 1 Answer