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.
The problem was that I was calling setBackground() inside my View's onSizeChanged(). I refactored the code and it works now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With