Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I draw outside the bounds of an Android Canvas

I'm porting an app written in a graphics environment that allows drawing to happen outside the bounds of the clipping rectangle. Any way to do this in Android?

like image 770
Mark Avatar asked Oct 26 '10 21:10

Mark


People also ask

Can we draw directly on Canvas in android studio?

The parameter to onDraw() is a Canvas object that the view can use to draw itself. The Canvas class defines methods for drawing text, lines, bitmaps, and many other graphics primitives. You can use these methods in onDraw() to create your custom user interface (UI).

How does Canvas work on Android?

The Canvas class holds the "draw" calls. To draw something, you need 4 basic components: A Bitmap to hold the pixels, a Canvas to host the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect, Path, text, Bitmap), and a paint (to describe the colors and styles for the drawing).

How do I draw a square in Canvas android?

The Canvas object provides the bitmap on which you draw. It also provides methods like "drawARGB()" for drawing a color, drawBitmap() method to draw a Bitmap, drawText() to draw a text and drawRoundRect() to draw a rectangle with round corners.


2 Answers

try to set

android:clipChildren="false"  

to the parent view

like image 117
Danylo.Vus Avatar answered Nov 09 '22 23:11

Danylo.Vus


To draw outside the bounds, you need to expand the clipRect of the canvas.

Check out the overloaded clipRect methods on the Canvas class.

Note - You will need to specify the Region operation because the default operation is INTERSECT. So something like this:

Rect newRect = canvas.getClipBounds(); newRect.inset(-5, -5)  //make the rect larger  canvas.clipRect (newRect, Region.Op.REPLACE); //happily draw outside the bound now 
like image 29
numan salati Avatar answered Nov 09 '22 23:11

numan salati