You can also use an array of colors and variable positions.
For example, define 10 colors, one each 10% progress:
<color name="color_0">#3C3C3F41</color>
<color name="color_10">#1AFF2323</color>
<color name="color_20">#33FF2323</color>
<color name="color_30">#4DFF2323</color>
<color name="color_40">#66FF2323</color>
<color name="color_50">#80FF2323</color>
<color name="color_60">#99FF2323</color>
<color name="color_70">#B3FF2323</color>
<color name="color_80">#CCFF2323</color>
<color name="color_90">#E6FF2323</color>
<color name="color_100">#FFFF2323</color>
将所有这些颜色都归到有色的阿雷拉。
var colors = intArrayOf(
ContextCompat.getColor(context, R.color.color_0),
ContextCompat.getColor(context, R.color.color_10),
ContextCompat.getColor(context, R.color.color_20),
ContextCompat.getColor(context, R.color.color_30),
ContextCompat.getColor(context, R.color.color_40),
ContextCompat.getColor(context, R.color.color_50),
ContextCompat.getColor(context, R.color.color_60),
ContextCompat.getColor(context, R.color.color_70),
ContextCompat.getColor(context, R.color.color_80),
ContextCompat.getColor(context, R.color.color_90),
ContextCompat.getColor(context, R.color.color_100)
)
然后界定立场。 位置从0.0到1.0(表0.1与颜色为10,位置为0.2至肤色为20等)
var positions = floatArrayOf(0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f)
一旦我们确定立场,我们就能够把瑞普梯落到我们的油漆中。
Shader gradient = new SweepGradient (0,getMeasuredHeight()/2, colors, positions);
lightRed.setShader(gradient);
最后,我们可以用我们的粉碎画 draw:
canvas.drawArc(rectf, -90, 360, false, lightRed);
我的习俗认为,最后生效: