SweepGradient ArrayIndexOutOfBoundsException异常

SweepGradient ArrayIndexOutOfBoundsException

我创建了一个这样的SweepGradient

int[] colors = { Color.RED, Color.BLUE };
// float[] positions = {0,1}; => this will work without error
float[] positions = { 0 , 280f/360 };
SweepGradient gradient = new SweepGradient(width / 2, height / 2, colors, positions);

当我设置 float[] positions = {0,1} 时,它会正常工作(没有错误)。
当我更改为 float[] positions = { 0 , 280f/360 } 时,在 Preview mode of AndroidStudio 中显示渲染错误,但在模拟器中它工作正常 为什么会这样?我该如何解决?

    int colors[] = {Color.RED, Color.BLUE, Color.BLUE};
    float positions[] = {0.f, 280f / 360, 1.f};

确保 positoins 数组跨越整个范围,即 [0.f, 1.0f]。现在预览也能正确显示了。

可能为空。每个对应颜色在colors数组中的相对位置,从0开始到1.0结束。