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

匿名 (未验证) 提交于 2019-12-03 02:49:01

问题:

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 instance, if innerRadiusRatio=9, then the inner radius equals the ring's width divided by 9 As I understand this means that innerRadiusRatio = 2*R1 / R2.

About thicknessRatio there is that: Thickness of the ring expressed as a ratio of the ring's width. For instance, if thicknessRatio=3, then the thickness equals the ring's width divided by 3. So thicknessRatio = 2*R1 / (R1 - R2).

thicknessRatio*(1-2/innerRadiusRatio)=2 which means that there is a connection between thicknessRatio and innerRadiusRatio. But there is nothing about this connection in GradientDrawable class documentation. And it doesn't seem that there is any connections between them as I can set thicknessRatio and innerRadiusRatio which doesn't satisfying last equation.

So tell me please where I'm wrong in my consideration or what are this parameters really responsible for?

回答1:

Ratios are a comparison of two numbers, so the above two equations can be rewritten as

Ratio1 = InnerRadius : Ring Width (where Ratio1 = InnerRadiusRatio)

Ratio2 = Thickness : Ring Width (where Ratio2 = ThicknessRatio)

Which means...

Ring Width = Ratio1 x Inner Radius = Ratio2 x Thickness

The "2" appeared since you added it into your equation. The only common denominator in all equation is "Ring Width". Trying it out with real numbers helps too.



回答2:

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:

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).



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!