Android LinearGradient

Bitmap    mBitmap;
Matrix    mShadowPaint;
Matrix    mLinearGradientMatrix;
LinearGradient    mLinearGradient;

mBitmap = BitmapFactory.decodeResource(getResource, R.drawable.jobs);

mShadowPaint = new Paint();
mShadowPaint.setStyle(Style.FILL);
mShadowPaint.setAlpha((int)0.9 * 255);

//渐变范围从(0, 0)到(1.0, 0)
//渐变颜色从红色到透明
//TileMode.CLAMP重复边缘色,这里实际是拉伸透明
mLinearGradient = new LinearGradient(0, 0, 1.0f, 0, Color.red, Color.TRANSPARENT, TileMode.CLAMP); 

mLinearGradientMatrix = new Matrix();
mLinearGradientMatrix.setScale(mBitmap.getWidth(), 1);
//把线性渐变的范围扩大到整张图片
mLinearGradient.setLocalMatrix(mLinearGradientMatrix);

mShadowPaint.setShader(mLinearGradient);

canvas.drawBitmap(mBitmap, 0, 0, null);
canvas.drawRect(0, 0, mBitmap.getWidth(), mBitmap.getHeight(), mShadowPaint);