androidandroid-drawableandroid-shape

Is that a bug in the Android documentation for the ring shape?


I've drawn a ring shape, here it is:

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

I've specified no innerRadiusRatio or thicknessRatio attributes, so, according to the documentation (for innerRadiusRatio, for thicknessRatio), they are going to be 9 and 3, respectively.

However, when I retrieve the values programatically, they appear to be the other way around:

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

The output is:

thicknessRatio = 9.0

innerRadiusRatio = 3.0

I can't think of anything but a bug here.

Perhaps I am missing something?

And the resulting ring obviously seems to have its thickness less than its inner radius:

enter image description here


Solution

  • Looks like it is.

    And the resulting ring obviously seems to have its thickness less than its inner radius

    That's because these values are divisors of the width:

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

    And the documentation provided via the links in the question confirms the same, except for the default values, which are incorrect:

    the inner radius equals the ring's width divided by 9

    the thickness equals the ring's width divided by 3