Hacker News new | ask | show | jobs
by wruza 1485 days ago
As a follow up, I’d like to try expressing the same with constraints instead of a grid. E.g.:

$image is at the top left, xy-padded by P, which is 5% of its width. To the right of it x-padded by P on both sides is a $textblock, with a minimum width of that of the image, aligned by top. If their natural/defined minimums make them not fit the width of the screen, $textblock goes below the $socialbtns padded by P/2, aligned by width of $image. $socialbtns are below the image aligned to the left, y-padded by P/2.

This should be expressed more formally, but you get the idea. Why can’t we just do this and instead have to solve some unique puzzle by hand every time we need some layout?

(Made few edits to constraints, now seems fine)

1 comments

Android has ConstraintLayout with some of that, but it's just "spaces between sibling edges", not quite as flexible as you describe.