33

I am using AS since 4 years. After last update I observed unexpected auto-formatting of XML layout (while typing and with Code -> Reformat Code too).

Here is an example:

  1. When I started typing relative layout, it expanded start tag, width property, height property and closing tag in the same line.
  2. Properties starts after indentation.
  3. No space between views after reformat.

Question

  • Is this a feature in new AS? then how can I revert it back?
  • Did I change some setting? What setting should I modify to revert back? (I tried to find on google but could not find anything)

enter image description here

I am using Android Studio 3.2.1 Build #AI-181.5540.7.32.5056338, built on October 8, 2018

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
HBB20
  • 2,743
  • 1
  • 24
  • 35
  • Did you close the `DrawerLayout`? close everything which started then try the same thing again. – ʍѳђઽ૯ท Oct 17 '18 at 11:24
  • Yes, It is hidden under tip-box. – HBB20 Oct 17 '18 at 12:28
  • 6
    Please give some constructive comments for your downvotes. Silent downvotes are not helping the community. – HBB20 Oct 17 '18 at 12:41
  • This blog post explains when the problem started occurring (faulty upgrade code from Google in Android Studio 3.5) and how to fix it: https://commonsware.com/blog/2019/08/21/android-studio-3p5-xml-reformatting-problems.html – Andrew Koster Sep 29 '19 at 22:51

2 Answers2

40

Update

if you facing same issue with Android Studio 3.5 please check below article

Android Studio 3.5 Upgrade XML Reformatting Problems

Open File > Settings > Editor > Code Style > XML

Now in layout file make sure you have selected wrap attributes as Wrap always

Like below screenshot:

enter image description here

Community
  • 1
  • 1
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
  • 2
    For me it was not using custom style. I enabled it and also checked the option "Insert line break before attribute" checked. It worked. – HBB20 Oct 17 '18 at 12:39
  • 1
    Same issue with me. By default it wasn't using custom style. Thanks to @NileshRathod for this answer! – mumayank Dec 05 '18 at 07:12
  • 10
    For me, changing that Scheme from Project to Default would do the trick – phapha pha Mar 19 '19 at 03:33
32

for me it's working

Open Settings > Editor > Code Style > XML > Arrangements
Click Set from... text
Select Predefined Styles > Android
Click Apply button

open preferences

go to XML code style

set predefined Android style

crusy
  • 1,424
  • 2
  • 25
  • 54
RITESH KUMAR
  • 1,070
  • 10
  • 10