这是Android文档中关于戒指形状的bug吗?

dauxcl2d  于 2023-10-14  发布在  Android
关注(0)|答案(1)|浏览(136)

我画了一个环形,在这里:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:shape="ring"
  4. android:useLevel="false">
  5. <solid android:color="@android:color/holo_blue_light" />
  6. <size
  7. android:width="200dp"
  8. android:height="200dp" />
  9. </shape>

我没有指定innerRadiusRatiothicknessRatio属性,因此,根据文档(对于innerRadiusRatio,对于thicknessRatio),它们将分别为9和3。
然而,当我以图解的方式检索这些值时,它们似乎是相反的:

  1. val ring = ContextCompat.getDrawable(this, R.drawable.ring) as GradientDrawable
  2. Log.i(TAG, "thicknessRatio = ${ring.thicknessRatio}")
  3. Log.i(TAG, "innerRadiusRatio = ${ring.innerRadiusRatio}")

输出为:
thicknessRatio = 9.0
innerRadiusRatio = 3.0
我什么都想不起来除了一只虫子。
也许我错过了什么?
由此产生的环显然看起来其厚度小于其内径:

izkcnapc

izkcnapc1#

看起来是的
由此产生的环,显然看起来厚度小于内径
这是因为这些值是宽度的约数:

  1. float thickness = st.mThickness != -1 ?
  2. st.mThickness : bounds.width() / st.mThicknessRatio;
  3. // inner radius
  4. float radius = st.mInnerRadius != -1 ?
  5. st.mInnerRadius : bounds.width() / st.mInnerRadiusRatio;

通过问题中的链接提供的文档也证实了这一点,除了默认值不正确:
内半径等于环的宽度除以9
厚度等于戒指的宽度除以3

相关问题