I\'m trying to modify the SurfaceView I use for doing a camera preview in order to display an overlaying square. However, the onDraw method of the extended SurfaceView is ne
Minor correction:
Adding setWillNotDraw(false) to the constructor will cause crashes, because the underlying Surface object is not created yet.
Instead, put the setWillNotDraw(false) statement into the surfaceCreated() method. This delays the call until there's a real object to work with, and works properly.
(and many thanks to the users who posted this solution, it solved a major problem for me)
Romain Guy explained it:
For efficiency, layouts do not get their
onDraw()
method called. To enable it, callsetWillNotDrawEnabled(false)
(or set the equivalent XML attribute to false.)
Based on all above comments I used :
Add setWillNotDraw(false) in the onAttachedToWindow() event.
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
setWillNotDraw(false);
}
and it worked.
Found it on the android-developers Google group. You simply have to add :
setWillNotDraw(false)
To the constructor. Now if someone could explain me why, that would be greatly appreciated.