Recent Changes‎ > ‎

Extract as Include Refactoring

posted Jan 7, 2011, 2:54 PM by Tor Norbye   [ updated Jan 7, 2011, 3:11 PM ]
The Layout Editor has a new refactoring which allows you to select one or more views in a layout, and extract it into a separate layout. A new layout file is created with the selected views, and an <include> tag pointing to the new layout is inserted where the views used to appear.

This makes it easy to share visual elements between different layouts, which is particularly useful if you have various configuration versions (such as one layout for portrait mode, and one for landscape mode).

Here's how it works. Let's say you have a layout like this:

We'd like to extract the bottom message area into a separate layout. Right click on the LinearLayout containing the 3 label/field/button views and choose "Extract as Include":

You will then be prompted for a name for the new layout. If you've selected a single view to extract, and it has an id, then this id is suggested as a layout name:

When you hit OK, the views are pulled out of the old layout, a new layout file created with the formatting adjusted, the namespace declarations carried over, and the original views replaced by an <include> tag referencing the new layout. The new extracted layout is opened:

As you can see from the outline this is a standalone view with just the send area widgets. The original layout still looks the same, but the outline reveals that we are now looking at just an include:

Note that you can select multiple views to extract, provided they are adjacent siblings. When you extract multiple root elements, they will be added under a <merge> tag in the extracted layout.