我想以编程方式在我视图的某个地方绘制一个渐弱的边缘,我只是复制了android视图系统的淡化边缘功能,但它无法工作,有什么建议吗?
mShaderPaint = new Paint();
mMatrix = new Matrix();
mShader = new LinearGradient(0, 0, 0, 1, 0xFF000000, 0, Shader.TileMode.CLAMP);
mShaderPaint.setShader(mShader);
mShaderPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
mFadingRect = new RectF();
// in dispatchDraw
final int sc = canvas.getSaveCount();
final int flags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG;
canvas.saveLayer(mFadingRect, null, flags);
mMatrix.setScale(1, (float)(.8 * mFadingEdgeLength));
mMatrix.postRotate(180);
mMatrix.postTranslate(mFadingRect.left, mFadingRect.bottom);
mShader.setLocalMatrix(mMatrix);
canvas.drawRect(mFadingRect, mShaderPaint);