What kind of connection exists between innerRadiusRatio and thicknessRatio from GradientDrawable class?

后端 未结 2 549
无人及你
无人及你 2021-02-01 10:46

Let\'s supposed we\'ve got a ring with inner radius R2 and outer radius R1. According documentation: Inner radius of the ring expressed as a ratio of the ring\'s width.For

2条回答
  •  走了就别回头了
    2021-02-01 11:05

    I know this is pretty late, but it may help others looking for this.

    In the documentation it says:

    Inner radius of the ring expressed as a ratio of the ring's width.

    The ring's width is not the Radius of the ring, it is the width of the view containing the ring. I draw this for an easier explanation:

    enter image description here

    That's the scheme of a view with a ring inside. The letters mean:

    • W: Width
    • P: Padding
    • Th: Thickness
    • Ir: Inner Radius.

    And I will add:

    • R: Radius.
    • IRR: InnerRadiusRatio.
    • THR: ThicknesRatio.

    The documentation actually describes the following relationship:

    • Ir = W/IRR
    • Th = W/THR

    So you can actually calculate the Radius.

    • R = Ir + Th = W (1/IRR + 1/THR).

    You can prove this by creating a view with a Ring that has:

    InnerRadiusRatio="4"
    ThicknessRatio="4".
    

    This will create a ring that has exactly the same width as the view.

    Note: All of the previous formulas are calculated with no padding. If there is padding on the View, you should replace every W with (W - P).

提交回复
热议问题