문제

I have a custom view being dynamically inserted and the onDraw is not being called. I initially made the custom view without the dynamic insertion and it worked fine, however when moving it to my working code base, I cannot get onDraw to get called ever, even though the view constructor gets called and the onMeasure also gets called. I've tried putting invalidate() and postInvalidate() calls around the place, but they don't seem to force the view to draw. The view hierarchy looks the same for both version and I'm lost.

Can anyone help?

EDIT: A bit more testing has shown that onDraw is getting called on the emulator, but not the handset. Also onSizeChanged on the handset has the correct values coming through, but on the emulator the values are all 0.

EDIT: I've been playing about with it and still can't get anywhere, so have put a bounty on it. If you need more code / xml / info then please let me know.

도움이 되었습니까?

해결책 2

I changed the View to a TextView and it seems to work now, although I'm a little confused as to why the View didn't work.

다른 팁

This sounds a lot like a problem i had recently, with my first custom view. Did you notice if, when loading view hierarchy, your custom views show up? and anyway do they appear laid out in the wireframe preview or not?

If the latter is the case, it's requestLayout() that doesn't get called (loading view hierarchy calls that on every view - that's why it makes views show up). i've also found that a similar bug was reported already here.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top