MHogge
MHogge

Reputation: 5196

Is their a "region-like" folding feature for Android Studio

I'm developing on Android Studio and as others IDE, Android Studio has a feature to create "regions" in the java code that can be folded. (see below)

With this kind of code

//region INITIALIZATION
private int myVaribale;
private String otherVariblae;
//endregion

We can fold/unfold the code (see screenshots below).

Unfolded code

Folded code

Is their something similar for XML editors (specially the one in Android Studio) ?

Something where we can add for example :

<!-- region MY LAYOUTS -->
<RelativeLayout>

   //Some layouts

</RelativeLayout>
<!-- endregion -->

Upvotes: 34

Views: 11892

Answers (5)

mtrakal
mtrakal

Reputation: 6427

You can use CTRL+ALT+T shortcut to generate Region/Editor folds.

Or your custom shortcut defined for: Settings > Keymap > Main Menu > Code > Surround With...

It works in Kotlin/Java/XML,etc. so you can create folds to Styles/layouts too.

Upvotes: 5

Danish Amjad
Danish Amjad

Reputation: 302

You can simply achieve this by

//region name
~~~Code~~~
//endregion

Check it out this link for more info. Create Regions in Android Studio

Upvotes: 15

Gary McGowan
Gary McGowan

Reputation: 1681

You can now do this:

<!--region Title-->
<View
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
<!--endregion-->

(I'm using Android Studio 3.0 and not sure when it was supported)

Upvotes: 60

Null Null
Null Null

Reputation: 11

Highlight code and press ctrl+ "."

Upvotes: 1

Geralt_Encore
Geralt_Encore

Reputation: 3771

Android Studio's XML editor supports only folding on IDE level with Cmd+Alt+"+" or "-".

Upvotes: 2

Related Questions