0

In my custom Android view, I will at some point call requestLayout() after I've changed my layout parameters. I'm overriding onDraw(...) so I also need to make sure invalidate() is called.

However, is it necessary to call invalidate() after requestLayout()?

Say that I don't, and I trust Android to do it for me after requestLayout(). It may be that what I've changed in my layout parameters changed nothing at all. Will Android detect this and avoid calling invalidate() in this edge case, or am I guaranteed that invalidate() will be called no matter what?

Edit: This is not a duplicate of Usage of forceLayout(), requestLayout() and invalidate(). I am specifically asking if there is some exempt in the Android code, e.g. if (newWidth == oldWidth && newHeight == oldHeight) return; // no need to invalidate? I would still like to invalidate even if my layout parameters did not change. In other words, does Android docs somewhere guarantee that invalidation will occur?

Community
  • 1
  • 1
HelloWorld
  • 2,770
  • 2
  • 26
  • 41
  • I think this is enough - http://stackoverflow.com/questions/13856180/usage-of-forcelayout-requestlayout-and-invalidate/13858255 – Paresh P. Jan 31 '17 at 10:17
  • 1
    You can check if `isDirty` and then decide wheter to call `invalidate` or not. I believe `invalidate` don't check for anything. – Anis LOUNIS Feb 01 '17 at 01:18
  • [please refer this](https://stackoverflow.com/a/25846243/8873646) think it will helpful for you..! – Machhi Sudke Feb 24 '18 at 12:50

0 Answers0