2 momo1199 Momo1199 于 2013.05.30 14:59 提问

实现视图和绘制的尺寸完全一致

在自定义View中的onDraw代码如下。

我要画一个对话气泡,

希望实现视图的尺寸和我画的泡泡是完全一样的。

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);
    }

1个回答

Kakalapa1986
Kakalapa1986   2013.05.30 15:56
已采纳
canvas.clipPath(path) 
canvas.drawPath(path, paint);
//TODO
canvas.save();
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!