应用alpha渐变

时间:2011-06-17 21:35:11

标签: android graphics

我正在使用这个

    public void drawSky(Canvas canvas) {

    float lineY =(CamOverlayTest.camViewCenterY/2)+3*(Math.max(0,(-90 - CamOverlayTest.swRoll)));

    int[] gColor = {Color.BLUE,Color.BLACK};

    GradientDrawable gradient = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP,gColor );
    gradient.setGradientType(GradientDrawable.LINEAR_GRADIENT);
    // gradient.setDither(true);
    Rect bounds = new Rect();
    bounds.set(CamOverlayTest.camViewCenterX-120, 0, CamOverlayTest.camViewCenterX+120, (int)lineY-2);
    gradient.setBounds(bounds);
    gradient.draw(canvas);
    }

画一个蓝天变成黑色,但我也希望它也有一个alpha渐变,但我的大脑无法解决如何做到这一点。

我基本上希望渐变开始透明然后变得完全不透明以及从蓝色变为黑色

请提出任何想法:)

西蒙

1 个答案:

答案 0 :(得分:2)

尝试替换此行:

int[] gColor = {0x000000FF,0xff000000};

每种颜色的前两位数字代表alpha。

您可能需要设置像素格式:

getWindow().setFormat(PixelFormat.RGBA_8888);

相关问题