gpt4 book ai didi

android - 使 View 的大小完全适合我在其中绘制的路径

转载 作者:行者123 更新时间:2023-11-29 21:41:58 26 4
gpt4 key购买 nike

这是我自定义 View 中的 onDraw 代码。我用路径绘制对话泡泡,我希望 View 的大小与我绘制的对话泡泡完全相同

protected void onDraw(Canvas canvas) {

super.onDraw(canvas);


Paint paint = new Paint();

paint.setColor(Color.BLACK);
paint.setAntiAlias(true);

paint.setStrokeWidth(2);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setPathEffect(new CornerPathEffect(15) );
paint.setStyle(Paint.Style.FILL_AND_STROKE);

paint.setShader(new LinearGradient(0, 0, 0, getHeight(), Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));

Path path = new Path();

paint.setShadowLayer(4, 2, 2, 0x80000000);

path.moveTo(myPath[0].x, myPath[0].y);

for (int i = 1; i < myPath.length; i++){

path.lineTo(myPath[i].x, myPath[i].y);

}

path.close();
canvas.drawPath(path, paint);


}

我怎样才能做到这一点?
提前致谢!

最佳答案

canvas.clipPath(path) 
canvas.drawPath(path, paint);
//TODO
canvas.save();

关于android - 使 View 的大小完全适合我在其中绘制的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16828375/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com