I\'m getting java.lang.StackOverflowErrors when my view hierarchy is being drawn:
at android.view.View.draw(View.java:6880)
at android.view.
A better explanation of my crazy idea 5. I'm not saying it's a good idea :) but I wanted to clarify how it can be done.
We will create our own implementations for the basic layouts (LinearLayout, FrameLayout, RelativeLayout) and use them instead of the originals.
The new layouts will extend the original ones but override the draw()
function.
The original draw function calls dispatchDraw()
which calls drawChild()
- and only then you get to the draw()
of your child. This means the draw()
in each nesting adds 3 function calls. We will try to minimize it into 1 function call manually.
This is the disgusting part. Are you familiar with inline
functions? We theoretically try and make the calls to dispatchDraw()
and drawChild()
inline. Since java doesn't really support inline, the best way would be to manually make them inline (actually copy-paste the code inside into a single disgusting function).
Where does this get a bit complicated? The implementation we would take would come from Android sources. The problem is that these sources may have changed slightly between Android versions. So one would have to map these changes and make a set of switches in the code in order to behave exactly like in the original.
Seems too much work and it's one hell of a hack..