Module embedded_layout::layout::linear [−][src]
Expand description
Linear layout
A linear layout is a list of Views that are placed one after the other along
the horizontal or vertical axis.
The main flow when working with a LinearLayout is the following:
- Create the layout
- you need to choose which orientation you want your views arranged in
- pass in your views wrapped in a
ViewGroup.
- Optionally, set secondary alignment
- Optionally, set element spacing
- Call
LinearLayout::arrangeto finalize view placement - Align the layout object to where you want it to be displayed
- Call
drawto display the views
Orientation
When constructing a LinearLayout object, you need to choose an orientation along which
the views will be arranged. This can either be horizontal or vertical.
Examples:
Create a LinearLayout with two pieces of text, where one is below the other:
let text_style = MonoTextStyle::new(&FONT_6X9, BinaryColor::On); let _ = LinearLayout::vertical( Chain::new(Text::new("Hello,", Point::zero(), text_style)) .append(Text::new("World!", Point::zero(), text_style)), ) .arrange();
Secondary alignment
Secondary alignment means the alignment on the “other” axis:
- horizontal alignment in vertical linear layouts
- vertical alignment in horizontal linear layouts
By default, the secondary alignments are the following:
- Horizontal orientation:
vertical::Bottom - Vertical orientation:
horizontal::Left
Except for using the cascading (XtoY) secondary alignments, the LinearLayout will take up
as much space along the secondary alignment as the biggest element, i.e. vertical layouts
will be as wide as the widest view inside them.
Element spacing
It’s possible to modify how views are placed relative to one another.
- The default is
Tightwhich is equivalent toFixedMargin(0) FixedMargin(margin):marginpx distance between views, wheremargincan be negative to overlap viewsDistributeFill(size): force the primary layout size tosize, distribute views evenly
Re-exports
pub use spacing::ElementSpacing;pub use spacing::FixedMargin;Modules
Element spacing
Structs
Traits
Helper trait that describes a linear layout orientation.
Secondary alignment is used to align views perpendicular to the placement axis.