Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View.onMeasure() not called

I have a very simple custom View with onMeasure() overriden. My onMeasure() decides the size according to the background Drawable. When the View is first created from xml everything works normally. But then I set a different background programatically, so the View should resize. The View has now a different background, but it doesn't resize and onMeasure() is not called.

I tried everything - requestLayout(), forceLayout(), invalidate(), setLayoutParams() - without any effect. What am I doing wrong? I just want my View to resize.

like image 439
fhucho Avatar asked Oct 14 '11 12:10

fhucho


1 Answers

The problem was that I was calling setBackground() inside my View's onSizeChanged(). I refactored the code and it works now.

like image 68
fhucho Avatar answered Nov 28 '22 00:11

fhucho