fweigl
fweigl

Reputation: 22018

Android Studio: 'wrap in container' in XML layout

When editing XML layout files, Eclipse has a feature called 'wrap in container' (Reformat -> Android -> ...) that lets you select one or several Views and wrap a layout of your choice around it. Is there something similar in Android Studio?

Upvotes: 12

Views: 5310

Answers (3)

maxdownunder
maxdownunder

Reputation: 5639

Just came across this, and to complete Simas' answer:

using AS1.2, this is easy to achieve...

  1. to set up a Live Template, simply select the View in your layout XML that you wanna surround. Hit Alt+Shift+Z (surround-with)... a little popup appears. Click Configure Live Templates.... Or use File->Settings->Editor->Live Templates as described above.
  2. Select the html/xml section and hit the little +. Give it a name and description, then fill in template text:

    <LinearLayout android:orientation="$ORIENTATION$" android:layout_width="wrap_content" android:layout_height="wrap_content" > $SELECTION$ </LinearLayout>

  3. Click Edit variables, set Expression:complete(), Default value:vertical... hit OK. Then, find the Define' button for applicable context... and select XML.

You're all set now. To use the template, select the View that you wanna surround in the XML, hit Alt+Shift+Z (surround-with)... a little popup appears. Select the template you just defined... Done!

Upvotes: 5

Simas
Simas

Reputation: 44118

You can use Live Templates for that. Here's a nice article about them.

Edit:

New templates can be added through File->Settings->Editor->Live Templates.

To find the hotkey for your keymap go to File->Settings and write "Live template". For me it's CTRL + J .

Upvotes: 4

novembre
novembre

Reputation: 569

It's currently being implemented: Issue 69000: Add the "Wrap In" visual refactoring - Android Issue Tracker

Tor Norbye, Android Issue Tracker Mantainer:

We should implement the "Wrap In" visual refactoring.

Upvotes: 6

Related Questions