'wrapping buttons arranged in row

the thing I'm trying to achieve:

enter image description here

is there a way to determine whether a row of buttons (after creating another button) will get off the screen, and if so, create another row? (or another way to create an arragement of buttons such as the one shown on picture?)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source