DialogFragment: getting size change on pre-3.0 devices

MichaelMuegelMichaelMuegel US ✭✭
edited October 2012 in Xamarin.Android

DialogFragment LayoutChange event / OnLayoutChangeListener() is not available prior to Android 3.0. The only way I have come up with to detect dialog size changes as keyboard is shown is to use View sub-class OnSizeChanged() method. Is this really the only way?

This approach forces me to create an intermediate View just to capture this (since my dialog view is from a layout). It would be nice if some common "eventish" things in View were exposed as .NET events. For example, in this case create common View.SizeChanged event.

Answers

  • MichaelMuegelMichaelMuegel US ✭✭
    edited October 2012

    I stumbled on View.ViewTreeObserver.GlobalLayout event. This can be used to synthesize a size change event by keeping track of previous sizes. This is available all the way back to API Level 1.

  • Another benefit of GlobalLayout is that, unlike OnSizeChange(), all layout will have finished and sizes can be accurately inspected.

Sign In or Register to comment.