android shape ring 画一个多层嵌套的圆环

文章来自:http://blog.csdn.net/intbird 转载请说明出处

1.圆环如图:

在这里插入图片描述

2.解释说明:

仅当 android:shape="ring" 如下时才使用以下属性:

  • android:innerRadius
    尺寸。环内部(中间的孔)的半径,以尺寸值或尺寸资源表示。
  • android:innerRadiusRatio
    浮点型。环内部的半径,以环宽度的比率表示。例如,如果android:innerRadiusRatio=“5”,则内半径等于环宽度除以 5。此值被 android:innerRadius 覆盖。默认值为 9。
  • android:thickness
    尺寸。环的厚度,以尺寸值或尺寸资源表示。
  • android:thicknessRatio
    浮点型。环的厚度,表示为环宽度的比率。例如,如果android:thicknessRatio=“2”,则厚度等于环宽度除以 2。此值被 android:innerRadius 覆盖。默认值为 3。
  • android:useLevel
    布尔值。如果此属性用作 LevelListDrawable,则值为“true”。此属性的值通常应为“false”,否则无法显示形状。

note: 环的厚度和半径都是相对于整个圆来说的

  • innerRadiusRatio = 100, 则 圆心半径为 整圆100 / 系数100 = 1, 圆心很小

  • innerRadiusRatio = 1, 则 圆心半径为 整圆100 / 系数1 = 100, 圆心超大

  • thicknessRatio = 100, 则 圆环厚度为 整圆100/ 系数100 = 1, 厚度很小

  • thicknessRatio = 1,则 圆环厚度为 整圆100/ 系数1 = 100, 厚度超大

3.具体实现

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <item>
        <shape
            android:innerRadiusRatio="2.2"
            android:shape="ring"
            android:thicknessRatio="30"
            android:useLevel="false">
            <solid android:color="#474747" />
        </shape>
    </item>

    <item>
        <shape
            android:innerRadiusRatio="2.2"
            android:shape="ring"
            android:thicknessRatio="100"
            android:useLevel="false">

            <solid android:color="#323232" />
            <stroke
                android:width="2dp"
                android:color="@android:color/black" />
        </shape>
    </item>

    <item>
        <shape
            android:innerRadiusRatio="3.4"
            android:shape="ring"
            android:thicknessRatio="6.6"
            android:useLevel="false">
            <solid android:color="#1E1D20" />
        </shape>
    </item>

    <item>
        <shape
            android:innerRadiusRatio="3.3"
            android:shape="ring"
            android:thicknessRatio="90"
            android:useLevel="false">

            <solid android:color="#1E1D20" />
            <stroke
                android:width="1dp"
                android:color="#323232" />
        </shape>
    </item>

    <item>
        <shape
            android:innerRadiusRatio="3.5"
            android:shape="ring"
            android:thicknessRatio="70"
            android:useLevel="false">

            <solid android:color="@android:color/black" />
        </shape>
    </item>
</layer-list>

后续整理出多个drawable的使用
https://developer.android.com/guide/topics/resources/drawable-resource

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章