Day134–aspect ratio in ConstraintLayout

Constraint Height as a percentage of the parent

Jacky Tsang
1 min readDec 17, 2019

layout_constraintWidth_percent and layout_constraintHeight_percent : will set the size of this dimension as a percentage of the parent

If you want an image to occupy half of the screen, you can use layout_constraintHeight_percent in portrait mode.

Constraint Height to be the same as width

The ratio can be expressed either as:

  • a float value, representing a ratio between width and height
  • a ratio in the form “width:height”

--

--

No responses yet