Custom onDraw() method not called
Add setWillNotDraw(false)
in MyDrawableView constructor. Original answer is here.
Your View has a height of 0. You set your View to have height=wrap_content
, but your don't override onMeasure()
to tell the UI toolkit how big your View is.
You need to @Override
the OnMeasure(int, int)
method to specify the size of your view by calling setMeasuredDimension(int,int)
.
If you don't, the default method will set your view to have size width=0 height=0
. And therefore don't even try to call onDraw
at all.
The OnMeasure
method calls setMeasuredDimension(int,int)
which tells how big is your view.
(So you need to get the size of the android screen on the OnMeasure
method and call setMeasuredDimension
accordingly).
Just make layout_width
and layout_height
of the custom view some fix at initial time instead of wrap_content
or fill_parent
.
That worked for me.