Android - ConstraintLayout percentage using dimens Android - ConstraintLayout percentage using dimens android android

Android - ConstraintLayout percentage using dimens


Instead of using a dimen resource, use an item resource of type dimen:

<item name="guideline_perc" type="dimen">0.5</item>

If using integers, an integer resource would work best:

<integer name="guideline_perc">1</integer>


To set a percentage use the fraction syntax

<fraction name="guideline_perc">0.5</fraction>

and then

app:layout_constraintGuide_percent="@fraction/guideline_perc"


Now in 2021 dimen float works fine. Just autocompletion in Android studio in that case doesn't. Don't know why.

app:layout_constraintGuide_percent="@dimen/guideline_perc"