Recent Changes‎ > ‎

    "Remove Container" Visual Refactoring

    posted Sep 13, 2011, 5:34 PM by Tor Norbye   [ updated Sep 13, 2011, 6:43 PM ]
    There's a new visual refactoring in the latest builds: "Remove Container". This is the logical opposite of the "Wrap In" refactoring. Where as "Wrap In" will surround the selected views with a new layout (and transfer layout and namespace attributes), the "Remove Container" will remove the given container such that its children are placed directly in the parent of the removed container.

    Here's an example. Let's say you have a ScrollView widget inside a LinearLayout, but you realize that you really want the ScrollView to be the root element:
    (By the way, when working with ScrollViews that's usually what you want. In the layout editor we special case the scenario where ScrollViews are the root element and render the full required size of all the children instead of just the current device screen size, such that you can see exactly what you're designing and what the scrollview viewport will be scrolling over, rather than just the visible viewport. Even if you want some other content next to your scroll view, you may want to use our include-support along with the Extract Include refactoring to isolate your ScrollView into its own layout XML file.)

    You can now bring up the context menu (or the main refactoring menu) and invoke the "Remove Container" visual refactoring:
    This will show the refactoring preview dialog which shows the transformation made to the source - which in addition to removing the container element, will also transfer the XML namespace attribute (if removing the root element) and transfer layout attributes:

    As with all the visual refactorings, you can also invoke this via the quickfix command when working directly with XML:
    The refactoring will also reformat the affected XML, and that's now done for all the visual refactorings, not just this one.