1

I am trying to make a view to recalculate its dimensions on demand. I have a view that uses a width and/or height with the value of ?attr:actionBarSize (it can be any variable that changes according to the screen orientation), but once the view is drawn after launching the app that view will never re-calculate again that value based on the screen orientation after the user rotates the screen.

Is it possible to force the view to recalculate its dimensions by reading the new value or is this possible by creating a custom view that can allow this to be done and causing all of its child views to recalculate their dimensions based on the parent view changes?

Forgot to include an important detail; the Activity cannot be restarted and recreate() cannot be used.

Shadow
  • 4,168
  • 5
  • 41
  • 72
  • https://stackoverflow.com/questions/15013445/android-view-viewgroup-invalidate-ondraw-and-draw – vikas kumar Nov 27 '17 at 03:47
  • @vikaskumar that question appears to be specifically focused on ViewGroup, whereas this one is for Views. – Shadow Nov 27 '17 at 08:42
  • Calling `view.invalidate()` would make the view and all of its children to pass another measure/layout/draw stage. – azizbekian Nov 27 '17 at 08:56
  • @azizbekian It does not work when I try it with a toolbar view that is in a xmlo layout, appears to completely ignore the call. This means that on landscape the toolbar should be smaller after calling invalidate, since that is how the default theme is designed, yet it does absolutely nothing. It is as if the view (s) are not recalculating the `?attr:actionBarSize` for that screen orientation. – Shadow Nov 27 '17 at 09:34

1 Answers1

0

It appears Android does not provide any method to do this, so I was forced to change the view manually and iterate all child views and change them manually as well.

Shadow
  • 4,168
  • 5
  • 41
  • 72