pskink's suggestion 是对的。您可以使用ArgbEvaluator 来实现此目标。
假设这是你的SeekBar:
C1 C2 C3
+-------|-------|-------|-------|---+---|-------|-------|-------|-------+
1 2 3 4 5 6 7 8 9 10
你有10个Thumb位置(数字从1 - 10),3种颜色(+符号表示颜色的位置,C1、C2和C3表示颜色的名称)。
C1和C2之间的距离(以及C2和C3之间的距离)可以分为9个部分。这 9 件可以代表你的Thumb 职位:
C1 C2 C3
+-------|-------|-------|-------|---+---|-------|-------|-------|-------+
| | | | | | | | | | |
0/9 2/9 4/9 6/9 8/9 9/9 | | | | |
| | | | | |
0/9 1/9 3/9 5/9 7/9 9/9
因此,您的SeekBar 的值可以这样计算:
int c1 = 0xFFFF0000; // ARGB representation of RED
int c2 = 0xFFFFFF00; // ARGB representation of YELLOW
int c3 = 0xFF00FF00; // ARGB representation of GREEN
ArgbEvaluator evaluator = new ArgbEvaluator();
int thumb1 = (int) evaluator.evaluate(0f, c1, c2); // 0f/9f = 0f
int thumb2 = (int) evaluator.evaluate(2f / 9f, c1, c2);
int thumb3 = (int) evaluator.evaluate(4f / 9f, c1, c2);
int thumb4 = (int) evaluator.evaluate(6f / 9f, c1, c2);
int thumb5 = (int) evaluator.evaluate(8f / 9f, c1, c2);
int thumb6 = (int) evaluator.evaluate(1f / 9f, c2, c3);
int thumb7 = (int) evaluator.evaluate(3f / 9f, c2, c3);
int thumb8 = (int) evaluator.evaluate(5f / 9f, c2, c3);
int thumb9 = (int) evaluator.evaluate(7f / 9f, c2, c3);
int thumb10 = (int) evaluator.evaluate(1f, c2, c3); // 9f/9f = 1f