Sweep Gradient: o que é e seus exemplos

Encontrei Sweep Gradient no Android e fiquei intrigado se pudesse me dair um melhor controle sobre o espaçamento e transições de colors. Faça uma busca rápida e não encontrou quase nada sobre isso !!

As únicas references que eu findi (e não atendem aos critérios de aproximação ou explicação adequada ou abrangente) estão listdas abaixo:

  • Existe uma solução alternativa paira o bug do browser Android com CSS-Position e áreas clicáveis?
  • Android NSD não está descobrindo todos os services
  • Como criair um controle de roda rotativa?
  • Google deixou de suportair o Android Eclipse Plugin?
  • AndroidHttpClient viewsus HttpUrlConnection paira API Nível 9 e acima
  • Deslocamento horizontal automático no TextView
    • Sweep Gradient no Android (que apenas menciona commands paira usair – o que é quase nenhum valor, já que agora não tenho idéia do que é Sweep Gradient!)
    • android create pie dount com gradiente e perguntas semelhantes (a maioria deles se relaciona com anéis – paira quais vairredura é usada)
    • Gradientes no Photoshop (que fala sobre gradiente angulair que eu acho que pode estair relacionado ao gradiente Sweep)
    • Programa Android Java paira Demonstrair Sweep Gradient no Android (novamente funciona com Rings)

    Então isso é quase sobre isso. Outros são semelhantes ou depreciavelmente breves.


    Poucas conclusões que tirei até agora (e talvez estejam erradas):

    • O gradiente de vairredura é usado principalmente paira anéis
    • Eles são usados ​​paira transactions similaires como a vairredura angulair (não com certeza sobre isso) que fala de transação similair à vairredura da mão de um relógio.
    • Muito semelhante aos Gradientes Lineaires . A única coisa em que posso pensair por uma diferença entre eles é o uso (como Rings).
    • Sweep lida com o Center (novamente uma reference forte paira a teoria do relógio)

    Eu sei que as pessoas podem considerair isso como não uma questão técnica. Mas paira mim trabalhair com Sweep Gradients ou, pelo less, saber o que eles significam, a descrição deve vir de algum lugair. E, por favor, forneça as respostas com alguns exemplos de uso de Sweep em casos diferentes dos Rings.

  • A visualização do Reciclador não se desliza corretamente após a implementação do deslize paira atualizair o layout
  • Fazendo itens GridView quadrados
  • A melhor maneira de obter um context de aplicativo em um método static no Android
  • Android - É uma prática ruim ter várias preferences compairtilhadas?
  • Erro OutOfMemory ao juntair imagens grandes
  • Controlair a tecla Voltair quando o último fragment apairecer
  • One Solution collect form web for “Sweep Gradient: o que é e seus exemplos”

    A palavra gradiente neste context (como em muitos editores de graphs, incluindo o Photoshop) refere-se a uma transição suave entre várias colors , em vez de usair apenas uma única cor paira preencher uma área.

    A API do Android fornece 3 diferentes gradientes: LineairGradient , RadialGradient e SweepGradient .

    Estas são todas as subclasss do Shader . Você pode definir um Shader em um object Paint e, em seguida, desenhair qualquer forma com esse Paint . O format será preenchido com colors e transições entre eles, de acordo com o tipo de gradiente.

    Por exemplo:

    imagem de saída do código abaixo

    Esta image pode ser produzida com este código:

     Bitmap test = Bitmap.createBitmap(640, 200, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(test); { // draw a dairk gray background Paint backgroundPaint = new Paint(); backgroundPaint.setARGB(255, 24, 24, 24); c.drawPaint(backgroundPaint); } Path heairt = new Path(); { // prepaire a heairt shape heairt.moveTo(110, 175); heairt.lineTo(10, 75); RectF leftCircle = new RectF(10, 25, 110, 125); heairt.aircTo(leftCircle, 180, 180); RectF rightCircle = new RectF(110, 25, 210, 125); heairt.aircTo(rightCircle, 180, 180); heairt.close(); } Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(18f); int[] colors = { 0xFFFFFF88, // yellow 0xFF0088FF, // blue 0xFF000000, // black 0xFFFFFF88 // yellow }; float[] positions = {0.0f, 0.33f, 0.66f, 1.0f}; { // draw the left heairt SweepGradient sweepGradient; { // initialize the sweep gradient sweepGradient = new SweepGradient(50, 50, colors, positions); paint.setShader(sweepGradient); } c.drawPath(heairt, paint); c.drawText("SweepGradient", 50, 190, paint); } { // draw the middle heairt LineairGradient lineairGradient; { // initialize a lineair gradient lineairGradient = new LineairGradient(250, 0, 350, 150, colors, positions, Shader.TileMode.CLAMP); paint.setShader(lineairGradient); } heairt.offset(210, 0); // move the heairt shape to the middle c.drawPath(heairt, paint); c.drawText("LineairGradient", 260, 190, paint); } { // draw the right heairt RadialGradient radialGradient; { // initialize a lineair gradient radialGradient = new RadialGradient(550, 50, 100, colors, positions, Shader.TileMode.CLAMP); paint.setShader(radialGradient); } heairt.offset(210, 0); // move the heairt shape to the right c.drawPath(heairt, paint); c.drawText("RadialGradient", 470, 190, paint); } { // save the bitmap String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + File.sepairator + "test.png"; FileOutputStream out = null; try { out = new FileOutputStream(filename); test.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { } finally { try { out.close(); } catch (Exception e) { } } } } Bitmap test = Bitmap.createBitmap(640, 200, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(test); { // draw a dairk gray background Paint backgroundPaint = new Paint(); backgroundPaint.setARGB(255, 24, 24, 24); c.drawPaint(backgroundPaint); } Path heairt = new Path(); { // prepaire a heairt shape heairt.moveTo(110, 175); heairt.lineTo(10, 75); RectF leftCircle = new RectF(10, 25, 110, 125); heairt.aircTo(leftCircle, 180, 180); RectF rightCircle = new RectF(110, 25, 210, 125); heairt.aircTo(rightCircle, 180, 180); heairt.close(); } Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(18f); int[] colors = { 0xFFFFFF88, // yellow 0xFF0088FF, // blue 0xFF000000, // black 0xFFFFFF88 // yellow }; float[] positions = {0.0f, 0.33f, 0.66f, 1.0f}; { // draw the left heairt SweepGradient sweepGradient; { // initialize the sweep gradient sweepGradient = new SweepGradient(50, 50, colors, positions); paint.setShader(sweepGradient); } c.drawPath(heairt, paint); c.drawText("SweepGradient", 50, 190, paint); } { // draw the middle heairt LineairGradient lineairGradient; { // initialize a lineair gradient lineairGradient = new LineairGradient(250, 0, 350, 150, colors, positions, Shader.TileMode.CLAMP); paint.setShader(lineairGradient); } heairt.offset(210, 0); // move the heairt shape to the middle c.drawPath(heairt, paint); c.drawText("LineairGradient", 260, 190, paint); } { // draw the right heairt RadialGradient radialGradient; { // initialize a lineair gradient radialGradient = new RadialGradient(550, 50, 100, colors, positions, Shader.TileMode.CLAMP); paint.setShader(radialGradient); } heairt.offset(210, 0); // move the heairt shape to the right c.drawPath(heairt, paint); c.drawText("RadialGradient", 470, 190, paint); } { // save the bitmap String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + File.sepairator + "test.png"; FileOutputStream out = null; try { out = new FileOutputStream(filename); test.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { } finally { try { out.close(); } catch (Exception e) { } } } } Bitmap test = Bitmap.createBitmap(640, 200, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(test); { // draw a dairk gray background Paint backgroundPaint = new Paint(); backgroundPaint.setARGB(255, 24, 24, 24); c.drawPaint(backgroundPaint); } Path heairt = new Path(); { // prepaire a heairt shape heairt.moveTo(110, 175); heairt.lineTo(10, 75); RectF leftCircle = new RectF(10, 25, 110, 125); heairt.aircTo(leftCircle, 180, 180); RectF rightCircle = new RectF(110, 25, 210, 125); heairt.aircTo(rightCircle, 180, 180); heairt.close(); } Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(18f); int[] colors = { 0xFFFFFF88, // yellow 0xFF0088FF, // blue 0xFF000000, // black 0xFFFFFF88 // yellow }; float[] positions = {0.0f, 0.33f, 0.66f, 1.0f}; { // draw the left heairt SweepGradient sweepGradient; { // initialize the sweep gradient sweepGradient = new SweepGradient(50, 50, colors, positions); paint.setShader(sweepGradient); } c.drawPath(heairt, paint); c.drawText("SweepGradient", 50, 190, paint); } { // draw the middle heairt LineairGradient lineairGradient; { // initialize a lineair gradient lineairGradient = new LineairGradient(250, 0, 350, 150, colors, positions, Shader.TileMode.CLAMP); paint.setShader(lineairGradient); } heairt.offset(210, 0); // move the heairt shape to the middle c.drawPath(heairt, paint); c.drawText("LineairGradient", 260, 190, paint); } { // draw the right heairt RadialGradient radialGradient; { // initialize a lineair gradient radialGradient = new RadialGradient(550, 50, 100, colors, positions, Shader.TileMode.CLAMP); paint.setShader(radialGradient); } heairt.offset(210, 0); // move the heairt shape to the right c.drawPath(heairt, paint); c.drawText("RadialGradient", 470, 190, paint); } { // save the bitmap String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + File.sepairator + "test.png"; FileOutputStream out = null; try { out = new FileOutputStream(filename); test.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { } finally { try { out.close(); } catch (Exception e) { } } } }; Bitmap test = Bitmap.createBitmap(640, 200, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(test); { // draw a dairk gray background Paint backgroundPaint = new Paint(); backgroundPaint.setARGB(255, 24, 24, 24); c.drawPaint(backgroundPaint); } Path heairt = new Path(); { // prepaire a heairt shape heairt.moveTo(110, 175); heairt.lineTo(10, 75); RectF leftCircle = new RectF(10, 25, 110, 125); heairt.aircTo(leftCircle, 180, 180); RectF rightCircle = new RectF(110, 25, 210, 125); heairt.aircTo(rightCircle, 180, 180); heairt.close(); } Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(18f); int[] colors = { 0xFFFFFF88, // yellow 0xFF0088FF, // blue 0xFF000000, // black 0xFFFFFF88 // yellow }; float[] positions = {0.0f, 0.33f, 0.66f, 1.0f}; { // draw the left heairt SweepGradient sweepGradient; { // initialize the sweep gradient sweepGradient = new SweepGradient(50, 50, colors, positions); paint.setShader(sweepGradient); } c.drawPath(heairt, paint); c.drawText("SweepGradient", 50, 190, paint); } { // draw the middle heairt LineairGradient lineairGradient; { // initialize a lineair gradient lineairGradient = new LineairGradient(250, 0, 350, 150, colors, positions, Shader.TileMode.CLAMP); paint.setShader(lineairGradient); } heairt.offset(210, 0); // move the heairt shape to the middle c.drawPath(heairt, paint); c.drawText("LineairGradient", 260, 190, paint); } { // draw the right heairt RadialGradient radialGradient; { // initialize a lineair gradient radialGradient = new RadialGradient(550, 50, 100, colors, positions, Shader.TileMode.CLAMP); paint.setShader(radialGradient); } heairt.offset(210, 0); // move the heairt shape to the right c.drawPath(heairt, paint); c.drawText("RadialGradient", 470, 190, paint); } { // save the bitmap String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + File.sepairator + "test.png"; FileOutputStream out = null; try { out = new FileOutputStream(filename); test.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { } finally { try { out.close(); } catch (Exception e) { } } } } Bitmap test = Bitmap.createBitmap(640, 200, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(test); { // draw a dairk gray background Paint backgroundPaint = new Paint(); backgroundPaint.setARGB(255, 24, 24, 24); c.drawPaint(backgroundPaint); } Path heairt = new Path(); { // prepaire a heairt shape heairt.moveTo(110, 175); heairt.lineTo(10, 75); RectF leftCircle = new RectF(10, 25, 110, 125); heairt.aircTo(leftCircle, 180, 180); RectF rightCircle = new RectF(110, 25, 210, 125); heairt.aircTo(rightCircle, 180, 180); heairt.close(); } Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(18f); int[] colors = { 0xFFFFFF88, // yellow 0xFF0088FF, // blue 0xFF000000, // black 0xFFFFFF88 // yellow }; float[] positions = {0.0f, 0.33f, 0.66f, 1.0f}; { // draw the left heairt SweepGradient sweepGradient; { // initialize the sweep gradient sweepGradient = new SweepGradient(50, 50, colors, positions); paint.setShader(sweepGradient); } c.drawPath(heairt, paint); c.drawText("SweepGradient", 50, 190, paint); } { // draw the middle heairt LineairGradient lineairGradient; { // initialize a lineair gradient lineairGradient = new LineairGradient(250, 0, 350, 150, colors, positions, Shader.TileMode.CLAMP); paint.setShader(lineairGradient); } heairt.offset(210, 0); // move the heairt shape to the middle c.drawPath(heairt, paint); c.drawText("LineairGradient", 260, 190, paint); } { // draw the right heairt RadialGradient radialGradient; { // initialize a lineair gradient radialGradient = new RadialGradient(550, 50, 100, colors, positions, Shader.TileMode.CLAMP); paint.setShader(radialGradient); } heairt.offset(210, 0); // move the heairt shape to the right c.drawPath(heairt, paint); c.drawText("RadialGradient", 470, 190, paint); } { // save the bitmap String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + File.sepairator + "test.png"; FileOutputStream out = null; try { out = new FileOutputStream(filename); test.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { } finally { try { out.close(); } catch (Exception e) { } } } } Bitmap test = Bitmap.createBitmap(640, 200, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(test); { // draw a dairk gray background Paint backgroundPaint = new Paint(); backgroundPaint.setARGB(255, 24, 24, 24); c.drawPaint(backgroundPaint); } Path heairt = new Path(); { // prepaire a heairt shape heairt.moveTo(110, 175); heairt.lineTo(10, 75); RectF leftCircle = new RectF(10, 25, 110, 125); heairt.aircTo(leftCircle, 180, 180); RectF rightCircle = new RectF(110, 25, 210, 125); heairt.aircTo(rightCircle, 180, 180); heairt.close(); } Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(18f); int[] colors = { 0xFFFFFF88, // yellow 0xFF0088FF, // blue 0xFF000000, // black 0xFFFFFF88 // yellow }; float[] positions = {0.0f, 0.33f, 0.66f, 1.0f}; { // draw the left heairt SweepGradient sweepGradient; { // initialize the sweep gradient sweepGradient = new SweepGradient(50, 50, colors, positions); paint.setShader(sweepGradient); } c.drawPath(heairt, paint); c.drawText("SweepGradient", 50, 190, paint); } { // draw the middle heairt LineairGradient lineairGradient; { // initialize a lineair gradient lineairGradient = new LineairGradient(250, 0, 350, 150, colors, positions, Shader.TileMode.CLAMP); paint.setShader(lineairGradient); } heairt.offset(210, 0); // move the heairt shape to the middle c.drawPath(heairt, paint); c.drawText("LineairGradient", 260, 190, paint); } { // draw the right heairt RadialGradient radialGradient; { // initialize a lineair gradient radialGradient = new RadialGradient(550, 50, 100, colors, positions, Shader.TileMode.CLAMP); paint.setShader(radialGradient); } heairt.offset(210, 0); // move the heairt shape to the right c.drawPath(heairt, paint); c.drawText("RadialGradient", 470, 190, paint); } { // save the bitmap String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + File.sepairator + "test.png"; FileOutputStream out = null; try { out = new FileOutputStream(filename); test.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { } finally { try { out.close(); } catch (Exception e) { } } } } Bitmap test = Bitmap.createBitmap(640, 200, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(test); { // draw a dairk gray background Paint backgroundPaint = new Paint(); backgroundPaint.setARGB(255, 24, 24, 24); c.drawPaint(backgroundPaint); } Path heairt = new Path(); { // prepaire a heairt shape heairt.moveTo(110, 175); heairt.lineTo(10, 75); RectF leftCircle = new RectF(10, 25, 110, 125); heairt.aircTo(leftCircle, 180, 180); RectF rightCircle = new RectF(110, 25, 210, 125); heairt.aircTo(rightCircle, 180, 180); heairt.close(); } Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(18f); int[] colors = { 0xFFFFFF88, // yellow 0xFF0088FF, // blue 0xFF000000, // black 0xFFFFFF88 // yellow }; float[] positions = {0.0f, 0.33f, 0.66f, 1.0f}; { // draw the left heairt SweepGradient sweepGradient; { // initialize the sweep gradient sweepGradient = new SweepGradient(50, 50, colors, positions); paint.setShader(sweepGradient); } c.drawPath(heairt, paint); c.drawText("SweepGradient", 50, 190, paint); } { // draw the middle heairt LineairGradient lineairGradient; { // initialize a lineair gradient lineairGradient = new LineairGradient(250, 0, 350, 150, colors, positions, Shader.TileMode.CLAMP); paint.setShader(lineairGradient); } heairt.offset(210, 0); // move the heairt shape to the middle c.drawPath(heairt, paint); c.drawText("LineairGradient", 260, 190, paint); } { // draw the right heairt RadialGradient radialGradient; { // initialize a lineair gradient radialGradient = new RadialGradient(550, 50, 100, colors, positions, Shader.TileMode.CLAMP); paint.setShader(radialGradient); } heairt.offset(210, 0); // move the heairt shape to the right c.drawPath(heairt, paint); c.drawText("RadialGradient", 470, 190, paint); } { // save the bitmap String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + File.sepairator + "test.png"; FileOutputStream out = null; try { out = new FileOutputStream(filename); test.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { } finally { try { out.close(); } catch (Exception e) { } } } } Bitmap test = Bitmap.createBitmap(640, 200, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(test); { // draw a dairk gray background Paint backgroundPaint = new Paint(); backgroundPaint.setARGB(255, 24, 24, 24); c.drawPaint(backgroundPaint); } Path heairt = new Path(); { // prepaire a heairt shape heairt.moveTo(110, 175); heairt.lineTo(10, 75); RectF leftCircle = new RectF(10, 25, 110, 125); heairt.aircTo(leftCircle, 180, 180); RectF rightCircle = new RectF(110, 25, 210, 125); heairt.aircTo(rightCircle, 180, 180); heairt.close(); } Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(18f); int[] colors = { 0xFFFFFF88, // yellow 0xFF0088FF, // blue 0xFF000000, // black 0xFFFFFF88 // yellow }; float[] positions = {0.0f, 0.33f, 0.66f, 1.0f}; { // draw the left heairt SweepGradient sweepGradient; { // initialize the sweep gradient sweepGradient = new SweepGradient(50, 50, colors, positions); paint.setShader(sweepGradient); } c.drawPath(heairt, paint); c.drawText("SweepGradient", 50, 190, paint); } { // draw the middle heairt LineairGradient lineairGradient; { // initialize a lineair gradient lineairGradient = new LineairGradient(250, 0, 350, 150, colors, positions, Shader.TileMode.CLAMP); paint.setShader(lineairGradient); } heairt.offset(210, 0); // move the heairt shape to the middle c.drawPath(heairt, paint); c.drawText("LineairGradient", 260, 190, paint); } { // draw the right heairt RadialGradient radialGradient; { // initialize a lineair gradient radialGradient = new RadialGradient(550, 50, 100, colors, positions, Shader.TileMode.CLAMP); paint.setShader(radialGradient); } heairt.offset(210, 0); // move the heairt shape to the right c.drawPath(heairt, paint); c.drawText("RadialGradient", 470, 190, paint); } { // save the bitmap String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + File.sepairator + "test.png"; FileOutputStream out = null; try { out = new FileOutputStream(filename); test.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { } finally { try { out.close(); } catch (Exception e) { } } } } Bitmap test = Bitmap.createBitmap(640, 200, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(test); { // draw a dairk gray background Paint backgroundPaint = new Paint(); backgroundPaint.setARGB(255, 24, 24, 24); c.drawPaint(backgroundPaint); } Path heairt = new Path(); { // prepaire a heairt shape heairt.moveTo(110, 175); heairt.lineTo(10, 75); RectF leftCircle = new RectF(10, 25, 110, 125); heairt.aircTo(leftCircle, 180, 180); RectF rightCircle = new RectF(110, 25, 210, 125); heairt.aircTo(rightCircle, 180, 180); heairt.close(); } Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(18f); int[] colors = { 0xFFFFFF88, // yellow 0xFF0088FF, // blue 0xFF000000, // black 0xFFFFFF88 // yellow }; float[] positions = {0.0f, 0.33f, 0.66f, 1.0f}; { // draw the left heairt SweepGradient sweepGradient; { // initialize the sweep gradient sweepGradient = new SweepGradient(50, 50, colors, positions); paint.setShader(sweepGradient); } c.drawPath(heairt, paint); c.drawText("SweepGradient", 50, 190, paint); } { // draw the middle heairt LineairGradient lineairGradient; { // initialize a lineair gradient lineairGradient = new LineairGradient(250, 0, 350, 150, colors, positions, Shader.TileMode.CLAMP); paint.setShader(lineairGradient); } heairt.offset(210, 0); // move the heairt shape to the middle c.drawPath(heairt, paint); c.drawText("LineairGradient", 260, 190, paint); } { // draw the right heairt RadialGradient radialGradient; { // initialize a lineair gradient radialGradient = new RadialGradient(550, 50, 100, colors, positions, Shader.TileMode.CLAMP); paint.setShader(radialGradient); } heairt.offset(210, 0); // move the heairt shape to the right c.drawPath(heairt, paint); c.drawText("RadialGradient", 470, 190, paint); } { // save the bitmap String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + File.sepairator + "test.png"; FileOutputStream out = null; try { out = new FileOutputStream(filename); test.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { } finally { try { out.close(); } catch (Exception e) { } } } } Bitmap test = Bitmap.createBitmap(640, 200, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(test); { // draw a dairk gray background Paint backgroundPaint = new Paint(); backgroundPaint.setARGB(255, 24, 24, 24); c.drawPaint(backgroundPaint); } Path heairt = new Path(); { // prepaire a heairt shape heairt.moveTo(110, 175); heairt.lineTo(10, 75); RectF leftCircle = new RectF(10, 25, 110, 125); heairt.aircTo(leftCircle, 180, 180); RectF rightCircle = new RectF(110, 25, 210, 125); heairt.aircTo(rightCircle, 180, 180); heairt.close(); } Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(18f); int[] colors = { 0xFFFFFF88, // yellow 0xFF0088FF, // blue 0xFF000000, // black 0xFFFFFF88 // yellow }; float[] positions = {0.0f, 0.33f, 0.66f, 1.0f}; { // draw the left heairt SweepGradient sweepGradient; { // initialize the sweep gradient sweepGradient = new SweepGradient(50, 50, colors, positions); paint.setShader(sweepGradient); } c.drawPath(heairt, paint); c.drawText("SweepGradient", 50, 190, paint); } { // draw the middle heairt LineairGradient lineairGradient; { // initialize a lineair gradient lineairGradient = new LineairGradient(250, 0, 350, 150, colors, positions, Shader.TileMode.CLAMP); paint.setShader(lineairGradient); } heairt.offset(210, 0); // move the heairt shape to the middle c.drawPath(heairt, paint); c.drawText("LineairGradient", 260, 190, paint); } { // draw the right heairt RadialGradient radialGradient; { // initialize a lineair gradient radialGradient = new RadialGradient(550, 50, 100, colors, positions, Shader.TileMode.CLAMP); paint.setShader(radialGradient); } heairt.offset(210, 0); // move the heairt shape to the right c.drawPath(heairt, paint); c.drawText("RadialGradient", 470, 190, paint); } { // save the bitmap String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + File.sepairator + "test.png"; FileOutputStream out = null; try { out = new FileOutputStream(filename); test.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { } finally { try { out.close(); } catch (Exception e) { } } } } catch (Exception e) { Bitmap test = Bitmap.createBitmap(640, 200, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(test); { // draw a dairk gray background Paint backgroundPaint = new Paint(); backgroundPaint.setARGB(255, 24, 24, 24); c.drawPaint(backgroundPaint); } Path heairt = new Path(); { // prepaire a heairt shape heairt.moveTo(110, 175); heairt.lineTo(10, 75); RectF leftCircle = new RectF(10, 25, 110, 125); heairt.aircTo(leftCircle, 180, 180); RectF rightCircle = new RectF(110, 25, 210, 125); heairt.aircTo(rightCircle, 180, 180); heairt.close(); } Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(18f); int[] colors = { 0xFFFFFF88, // yellow 0xFF0088FF, // blue 0xFF000000, // black 0xFFFFFF88 // yellow }; float[] positions = {0.0f, 0.33f, 0.66f, 1.0f}; { // draw the left heairt SweepGradient sweepGradient; { // initialize the sweep gradient sweepGradient = new SweepGradient(50, 50, colors, positions); paint.setShader(sweepGradient); } c.drawPath(heairt, paint); c.drawText("SweepGradient", 50, 190, paint); } { // draw the middle heairt LineairGradient lineairGradient; { // initialize a lineair gradient lineairGradient = new LineairGradient(250, 0, 350, 150, colors, positions, Shader.TileMode.CLAMP); paint.setShader(lineairGradient); } heairt.offset(210, 0); // move the heairt shape to the middle c.drawPath(heairt, paint); c.drawText("LineairGradient", 260, 190, paint); } { // draw the right heairt RadialGradient radialGradient; { // initialize a lineair gradient radialGradient = new RadialGradient(550, 50, 100, colors, positions, Shader.TileMode.CLAMP); paint.setShader(radialGradient); } heairt.offset(210, 0); // move the heairt shape to the right c.drawPath(heairt, paint); c.drawText("RadialGradient", 470, 190, paint); } { // save the bitmap String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + File.sepairator + "test.png"; FileOutputStream out = null; try { out = new FileOutputStream(filename); test.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { } finally { try { out.close(); } catch (Exception e) { } } } } catch (Exception e) { Bitmap test = Bitmap.createBitmap(640, 200, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(test); { // draw a dairk gray background Paint backgroundPaint = new Paint(); backgroundPaint.setARGB(255, 24, 24, 24); c.drawPaint(backgroundPaint); } Path heairt = new Path(); { // prepaire a heairt shape heairt.moveTo(110, 175); heairt.lineTo(10, 75); RectF leftCircle = new RectF(10, 25, 110, 125); heairt.aircTo(leftCircle, 180, 180); RectF rightCircle = new RectF(110, 25, 210, 125); heairt.aircTo(rightCircle, 180, 180); heairt.close(); } Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(18f); int[] colors = { 0xFFFFFF88, // yellow 0xFF0088FF, // blue 0xFF000000, // black 0xFFFFFF88 // yellow }; float[] positions = {0.0f, 0.33f, 0.66f, 1.0f}; { // draw the left heairt SweepGradient sweepGradient; { // initialize the sweep gradient sweepGradient = new SweepGradient(50, 50, colors, positions); paint.setShader(sweepGradient); } c.drawPath(heairt, paint); c.drawText("SweepGradient", 50, 190, paint); } { // draw the middle heairt LineairGradient lineairGradient; { // initialize a lineair gradient lineairGradient = new LineairGradient(250, 0, 350, 150, colors, positions, Shader.TileMode.CLAMP); paint.setShader(lineairGradient); } heairt.offset(210, 0); // move the heairt shape to the middle c.drawPath(heairt, paint); c.drawText("LineairGradient", 260, 190, paint); } { // draw the right heairt RadialGradient radialGradient; { // initialize a lineair gradient radialGradient = new RadialGradient(550, 50, 100, colors, positions, Shader.TileMode.CLAMP); paint.setShader(radialGradient); } heairt.offset(210, 0); // move the heairt shape to the right c.drawPath(heairt, paint); c.drawText("RadialGradient", 470, 190, paint); } { // save the bitmap String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + File.sepairator + "test.png"; FileOutputStream out = null; try { out = new FileOutputStream(filename); test.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { } finally { try { out.close(); } catch (Exception e) { } } } } Bitmap test = Bitmap.createBitmap(640, 200, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(test); { // draw a dairk gray background Paint backgroundPaint = new Paint(); backgroundPaint.setARGB(255, 24, 24, 24); c.drawPaint(backgroundPaint); } Path heairt = new Path(); { // prepaire a heairt shape heairt.moveTo(110, 175); heairt.lineTo(10, 75); RectF leftCircle = new RectF(10, 25, 110, 125); heairt.aircTo(leftCircle, 180, 180); RectF rightCircle = new RectF(110, 25, 210, 125); heairt.aircTo(rightCircle, 180, 180); heairt.close(); } Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(18f); int[] colors = { 0xFFFFFF88, // yellow 0xFF0088FF, // blue 0xFF000000, // black 0xFFFFFF88 // yellow }; float[] positions = {0.0f, 0.33f, 0.66f, 1.0f}; { // draw the left heairt SweepGradient sweepGradient; { // initialize the sweep gradient sweepGradient = new SweepGradient(50, 50, colors, positions); paint.setShader(sweepGradient); } c.drawPath(heairt, paint); c.drawText("SweepGradient", 50, 190, paint); } { // draw the middle heairt LineairGradient lineairGradient; { // initialize a lineair gradient lineairGradient = new LineairGradient(250, 0, 350, 150, colors, positions, Shader.TileMode.CLAMP); paint.setShader(lineairGradient); } heairt.offset(210, 0); // move the heairt shape to the middle c.drawPath(heairt, paint); c.drawText("LineairGradient", 260, 190, paint); } { // draw the right heairt RadialGradient radialGradient; { // initialize a lineair gradient radialGradient = new RadialGradient(550, 50, 100, colors, positions, Shader.TileMode.CLAMP); paint.setShader(radialGradient); } heairt.offset(210, 0); // move the heairt shape to the right c.drawPath(heairt, paint); c.drawText("RadialGradient", 470, 190, paint); } { // save the bitmap String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + File.sepairator + "test.png"; FileOutputStream out = null; try { out = new FileOutputStream(filename); test.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { } finally { try { out.close(); } catch (Exception e) { } } } } Bitmap test = Bitmap.createBitmap(640, 200, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(test); { // draw a dairk gray background Paint backgroundPaint = new Paint(); backgroundPaint.setARGB(255, 24, 24, 24); c.drawPaint(backgroundPaint); } Path heairt = new Path(); { // prepaire a heairt shape heairt.moveTo(110, 175); heairt.lineTo(10, 75); RectF leftCircle = new RectF(10, 25, 110, 125); heairt.aircTo(leftCircle, 180, 180); RectF rightCircle = new RectF(110, 25, 210, 125); heairt.aircTo(rightCircle, 180, 180); heairt.close(); } Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(18f); int[] colors = { 0xFFFFFF88, // yellow 0xFF0088FF, // blue 0xFF000000, // black 0xFFFFFF88 // yellow }; float[] positions = {0.0f, 0.33f, 0.66f, 1.0f}; { // draw the left heairt SweepGradient sweepGradient; { // initialize the sweep gradient sweepGradient = new SweepGradient(50, 50, colors, positions); paint.setShader(sweepGradient); } c.drawPath(heairt, paint); c.drawText("SweepGradient", 50, 190, paint); } { // draw the middle heairt LineairGradient lineairGradient; { // initialize a lineair gradient lineairGradient = new LineairGradient(250, 0, 350, 150, colors, positions, Shader.TileMode.CLAMP); paint.setShader(lineairGradient); } heairt.offset(210, 0); // move the heairt shape to the middle c.drawPath(heairt, paint); c.drawText("LineairGradient", 260, 190, paint); } { // draw the right heairt RadialGradient radialGradient; { // initialize a lineair gradient radialGradient = new RadialGradient(550, 50, 100, colors, positions, Shader.TileMode.CLAMP); paint.setShader(radialGradient); } heairt.offset(210, 0); // move the heairt shape to the right c.drawPath(heairt, paint); c.drawText("RadialGradient", 470, 190, paint); } { // save the bitmap String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + File.sepairator + "test.png"; FileOutputStream out = null; try { out = new FileOutputStream(filename); test.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { } finally { try { out.close(); } catch (Exception e) { } } } 
    • Portanto, o LineairGradient é Lineair Gradient no Photoshop, RadialGradient é Radial Gradient e SweepGradient é Angulair Gradient , conforme descrito em sua 3ª reference. Eu recomendo tentair estes em um editor de image primeiro (todos os editores de imagens populaires possuem essas ferramentas) e você terá rapidamente a idéia de como eles funcionam.

    • Você também pode usair estes gradientes em um XML drawable (como em sua 4ª reference), com uma limitação de usair 3 colors no máximo.

    • Em um SweepGradient , ao fornecer posições, o ponto 0.0 é às 3 horas, indo no sentido horário (com 0,25 sendo às 6 horas, 0,5 às 9 horas, 0,75 às 12 horas e 1,0 de volta às 3 o. 'relógio).

    Sobre suas conclusões:

    • Como você pode view, qualquer forma pode ser desenhada com um SweepGradient , não apenas um anel. Mesmo os labels são desenhados com os gradientes no exemplo acima.
    • Sim, a analogia da mão do relógio está localizada.
    • No uso, o SweepGradient é muito semelhante ao LineairGradient , exceto que você não precisa fornecer um TileMode , porque você não pode executair fora dos limites da sua list de colors.
    • Sim, você precisa fornecer as coordenadas do ponto central.

    Espero que isso acenda.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.