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?
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).
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).
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.
try to set
android:clipChildren="false"
to the parent view
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With