Creating View Arrangements
Isolated Views hardly warrant a user’s attention—we’ve personally never downloaded a One Line of Text In The Middle of the Screen app, but maybe that’s just us. Let’s explore how ViewGroups and the attributes they define help us arrange multiple Views into valuable designs.
We will meet
LinearLayout, two of Android’s most well-known
ViewGroups; the former arranges Views relative to other Views, and the latter arranges them in straight lines. When we use
ViewGroups in tandem with Android’s cornucopia of interface components, we may form exceptionally complex designs without ever building a custom
- ConstraintLayout arranges its children relative to itself and other children (
LinearLayoutarranges its children in a straight line, either horizontally or vertically.
- Children of
ConstraintLayoutmust provide one horizontal and one vertical constraint to define their position within the
ConstraintLayoutis primarily ‘bottom-up,’ as it requires its children to supply position-related attributes, whereas
LinearLayoutis ‘top-down’ and dictates the final position to each child.
- Margins introduce space between Views, and Views often benefit from the “breathing room” margins provide.