Android自定义视图setShadowLayer onDraw递归调用

时间:2017-08-29 01:37:13

标签: android

我定义了自定义折线图,我想要绘制shadowLayer

 mFoldLinePaint.setStyle(Paint.Style.STROKE);
 mFoldLinePaint.setPathEffect(null);
 canvas.drawPath(mPath, mFoldLinePaint);
 mFoldLinePaint.setShader(new LinearGradient(line.getPoint(0).fLineX, line.getPoint(0).fLineY, line.getPoint(line.getSize() - 1).fLineX, line.getPoint(line.getSize() - 1).fLineY, mFoldLineGradientLeftColor, mFoldLineGradientRightColor, Shader.TileMode.MIRROR));
 setLayerType(LAYER_TYPE_SOFTWARE, null);
 mFoldLinePaint.setShadowLayer(5, 5, -5, Color.BLACK);

然后我遇到了问题

1.onDraw递归调用

2.黑色不起作用(阴影层工作) 任何人帮助我?

1 个答案:

答案 0 :(得分:0)

1.删除此代码setLayerType(LAYER_TYPE_SOFTWARE,null);从自定义视图 添加mView.setLayerType(LAYER_TYPE_SOFTWARE,null);在活动或片段

2.黑色不起作用(阴影层工作) drawPath两次

    mFoldLinePaint.setStyle(Paint.Style.STROKE);
    mFoldLinePaint.setPathEffect(null);
    mFoldLinePaint.setShader(new LinearGradient(line.getPoint(0).fLineX, line.getPoint(0).fLineY, line.getPoint(line.getSize() - 1).fLineX, line.getPoint(line.getSize() - 1).fLineY, mFoldLineGradientLeftColor, 
    mFoldLineGradientRightColor, Shader.TileMode.MIRROR));

    mFoldLinePaintVice.setStyle(Paint.Style.STROKE);
    mFoldLinePaintVice.setPathEffect(null);
    mFoldLinePaintVice.setShadowLayer(5, 5, -5, Color.BLACK);

    canvas.drawPath(mPath, mFoldLinePaintVice);
    canvas.drawPath(mPath, mFoldLinePaint);