Finding dynamic width isn't hard, but as previously mentioned you need a ratio. The rest is grade-school level algebra.
For instance, say that your items must be 2x the size of the space.
You start with:
item_width = 2*space_width
screen_width = item_count*item_width + (item_count-1)*space_width
Now you substitute in item_width for space_width:
screen_width = item_count*2*space_width + (item_count-1)*space_width
Simplify and solve for space_width:
space_width = screen_width/((3*item_count)-1)
Substitute back in for item_width:
item_width = 2*screen_width/((3*item_count)-1)
Now, if you don't just want items to be twice as wide as spaces, you need to iteratively solve a slightly more complex equation. In this situation, you need to know the minimum width of your items (how small can they be and still be drawable) and the maximum size or ratio you want.
Then you solve the above equation as written. Clamp the item_width to the minimum and maximum sizes. Then resolve for space_width using item_width:
space_width = (screen_width - (item_count*item_width)/(item_count-1)
And there you have a flexible system that will arrange item_count items in a row with variable width and spacing while maintaining some pleasant ratios and minimum dimensions. The harder problem then is to arrange some N items into multiple rows with a variable number per row. It's all just more algebra, though. You end up with more equations and more variables (your item_count becomes a variable instead of a constant, and you'll need minimum values and ratios for both item_width and space_width, and then solve for item_count after finding those). But it's just basic algebra.