Constraint layout, Linear layout

1) Constraint layout

Important parameters

1) layoutconstraintBottom

2) layoutconstraintEnd (Right)

3) layoutconstraintStart (Left)

4) layoutconstraintTop

5) layout_constraintHorizontal_bias

6) layout_constraintVertical_bias

The constraints can be added by playing with the connectors

Bias

1) Bias determines where the widget gets located in the constrained layout.

2) Horizontal bias gets activated when both left and right constraints are defined. (similarly top and bottom for vertical bias)

3) They can be controlled with the sliders in the attributes bar (or by dragging in the panel)

4) When both bias are 0.5 (default), widget is at the center for all screens and orientation

app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"

To place the widget at the bottom left corner for all screens and orientation, drag the bias sliders to bottom left (0.0 and 1.0)

app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0"

Margin

1) When only one of the top/bottom (or left/right) constrained is specified, that distance is added as margin

Eg, When we remove the bottom constrain, a specific pixel from top of screen is defined as we drag the widget. The look of the positioning might be different in different screens.

app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="136dp"

2) Linear layout

This layout is used when we want to position widgets next to each other (horizontally/vertically). The layout itself can be inside constrained layout and can be dragged as a whole

NOTE: (layout gravity) The widgets within linear layout will now have a new parameter called layout gravity. This is used to align each element within the linear layout

Linear layout vertical

1) Widgets can be ordered only one below the other

2) The button widget has layout gravity = center

Linear layout horizontal

1) Widgets can only be ordered next to each other