Apply an alpha gradient
I'm using this
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);
}
to draw a blue sky turning to black but I'd like it to also have an alpha gradient as well but my brain can't work out how to do it.
I basically want the gradient to start off transparent and then become fully opaque as well as changing from blue to black
Any ideas please :)
Simon
Try replacing this line:
int[] gColor = {0x000000FF,0xff000000};
The first two digits of each color represent alpha.
You may have to set a pixel format like so:
getWindow().setFormat(PixelFormat.RGBA_8888);
精彩评论