Search code examples
androidandroid-constraintlayoutaspect-ratio

How to set aspect ratio in xml (dimens.xml in values folder) to set different aspect ratio depending on devices?


Maybe a stupid question but in android how can I set aspect ratio in xml (dimens.xml in values folder) to set different aspect ratio depending on devices

I tried :

layout.xml

app:layout_constraintDimensionRatio="@dimen/common_image_aspect_ratio"

values/dimens.xml

<dimen name="common_image_aspect_ratio">3:2</dimen>

but it doesn't seem to work.

Any help would be appreciated, thx :)


Solution

  • Try to write 1.5 instead of 3:2. Generally, you should use decimal format, not fractional. Hope it will help.