Horizontal LinearGradient with android

前端 未结 1 1060
死守一世寂寞
死守一世寂寞 2020-12-14 05:55

This must be an easy one but I\'m really at a loss... The following code draws a rectangle with a linear gradient going from left to right, from white to black,

<         


        
相关标签:
1条回答
  • 2020-12-14 06:22

    I haven't done much android coding, but one approach worth trying is:

    int x1 = 0, y1 = 0, x2 = 0,  y2 = 40;
    

    The x never changes in the gradient only the y does.

    So what this might look like is:

    Shader shader = new LinearGradient(0, 0, 0, 40, Color.WHITE, Color.BLACK, TileMode.CLAMP);
    Paint paint = new Paint(); 
    paint.setShader(shader); 
    canvas.drawRect(new RectF(0, 0, 100, 40), paint); 
    
    0 讨论(0)
提交回复
热议问题