How to set gradient style to paint object?

前端 未结 2 1602
醉话见心
醉话见心 2020-12-04 17:52

The code for drawing an arrow with Style: Fill is given below:

paint.setColor(Color.parseColor(\"#bdc0dc\"));
paint.setStyle(Style.FILL);
canvas.dr         


        
相关标签:
2条回答
  • 2020-12-04 18:09

    use the code below..

    paint.setShader(new LinearGradient(0, 0, 0, getHeight(), Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));
        canvas.drawPath(arrowPath, paint);
    
    0 讨论(0)
  • 2020-12-04 18:17

    If you want more than one color:

    // Gradient Shade colors distribution setting uniform for now
    private val positions = null //floatArrayOf(0f, 0.3f, 0.6f)
    
    // Gradient Shade colors
    private val colors = intArrayOf(
            ContextCompat.getColor(context,
                    R.color.divider_gradient_start_color),
            ContextCompat.getColor(context,
                    R.color.divider_gradient_center_color),
            ContextCompat.getColor(context,
                    R.color.divider_gradient_end_color))
    

    in OnDraw()

    // Add Shader
    gradientPaint.shader = LinearGradient(0f, 0f, measuredWidth.toFloat(),0f, 
                    colors, 
                    positions,
                    Shader.TileMode.CLAMP)
    
    canvas.drawPath(path, gradientPaint)
    
    0 讨论(0)
提交回复
热议问题