Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 870
fweigl Avatar asked Jun 06 '14 10:06

fweigl


People also ask

How to enable wrap in Android Studio?

“how to wrap code in android studio” Code Answer "File->Settings->Editor->General" tab and check "Use soft wraps in editor".

How to wrap text in Android Studio code?

Please goto "File->Settings->Editor->General" tab and check "Use soft wraps in editor". it will solve your problem.

How to include another layout in XML Android?

To efficiently re-use complete layouts, you can use the <include/> and <merge/> tags to embed another layout inside the current layout. Reusing layouts is particularly powerful as it allows you to create reusable complex layouts.


3 Answers

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.

like image 102
novembre Avatar answered Oct 19 '22 21:10

novembre


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!

like image 45
maxdownunder Avatar answered Oct 19 '22 19:10

maxdownunder


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 .

like image 21
Simas Avatar answered Oct 19 '22 20:10

Simas