Reverse engineering (RE) of user interfaces (UIs) plays an important role in software evolution. However, the large diversity of UI technologies and the need for UIs to be resizable make this challenging. We propose ReverseORC, a novel RE approach able to discover diverse layout types and their dynamic resizing behaviours independently of their implementation, and to specify them by using OR constraints. Unlike previous RE approaches, ReverseORC infers fexible layout constraint specifcations by sampling UIs at diferent sizes and analyzing the diferences between them. It can create specifcations that replicate even some non-standard layout managers with complex dynamic layout behaviours. We demonstrate that ReverseORC works across diferent platforms with very diferent layout approaches, e.g., for GUIs as well as for the Web. Furthermore, it can be used to detect and fx problems in legacy UIs, extend UIs with enhanced layout behaviours, and support the creation of fexible UI layouts.