onDraw() on View draws behind the layout onDraw() on View draws behind the layout android android

onDraw() on View draws behind the layout


Well i found this out after going into a totally different direction =/

Here's the solution for people that have the same problem:

In constructor (or anywhere else you initialize the component) set setWillNotDraw(false) and override dispatchDraw(). dispatchDraw() draws the ViewGroup children so you can decide yourself if you want to draw behind or a top of the other views.

Example taken from Custom drawing on top of Gallery view (and it's child views)

@Overrideprotected void dispatchDraw(Canvas canvas) {    super.dispatchDraw(canvas);    // do your drawing stuff here    canvas.drawPath(mPath,mPaint);}