Litho uses Yoga which is an implementation of Flexbox to measure and layout components on screen. If you have used Flexbox on the web before this should be very familiar. If you are more familiar with how Android normally performs Layout then Flexbox will remind you a lot of LinearLayout.

In Litho you can use a Row to achieve a similar layout to a horizontal LinearLayout.

1
2
3
4
Row.create(c)
    .child(...)
    .child(...)
    .build();

Or a Column to achieve a similar layout to a vertical LinearLayout.

1
2
3
4
Column.create(c)
    .child(...)
    .child(...)
    .build();

To achieve an effect similar to a LinearLayout with weights Flexbox provides a concept called flexGrow(<weight>).

1
2
3
4
5
6
7
8
9
10
Row.create(c)
    .child(
        SolidColor.create(c)
            .color(RED)
            .flexGrow(1))
    .child(
        SolidColor.create(c)
            .color(BLUE)
            .flexGrow(1))
    .build();

If you would like to overlay one view on top of the other – similar to a FrameLayout – Flexbox can do that with positionType(ABSOLUTE).

1
2
3
4
5
6
7
8
9
10
11
Column.create(c)
    .child(
        Image.create(c)
            .srcRes(R.drawable.some_big_image)
            .widthDip(100)
            .heightDip(100))
    .child(
        Text.create(c)
            .text("Overlaid text")
            .positionType(ABSOLUTE))
    .build();

For more documentation of specific Flexbox properties check out the Yoga documentation or explore any web resources on how Flexbox works.

Edit on GitHub