Android - ConstraintLayout percentage using dimens

后端 未结 2 629
灰色年华
灰色年华 2021-02-19 18:47

There is a question How to make ConstraintLayout work with percentage values? and its answers show how to use the percentages:



        
相关标签:
2条回答
  • 2021-02-19 19:16

    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>

    0 讨论(0)
  • 2021-02-19 19:29

    To set a percentage use the fraction syntax

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

    and then

    app:layout_constraintGuide_percent="@fraction/guideline_perc"
    
    0 讨论(0)
提交回复
热议问题