Home > DeveloperSection > Forums > fit the size of view exactly to path i darw in it
Pravesh Singh

Total Post:411

Points:2881
Posted on    May-29-2013 11:55 PM

 Android Android 
Ratings:


 1 Reply(s)
 864  View(s)
Rate this:
Hi All,

this is onDraw code in my custom view
i draw the speech bubble with path
and i want the size of view exactly be the same as speech bubble i darw

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

how can do this?
Thanks for advance.


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    May-30-2013 5:38 AM

Hi Pravesh!

Try as following

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

canvas.save();

I hope this code might be resolve your problem. 

Don't want to miss updates? Please click the below button!

Follow MindStick