Accepted answer

this bug is (finally) fixed in adt 21. the fix is now available in adt 21 preview 9, posted a few minutes ago, here:

the reason you get weird visual artifacts is that if a file contains broken dos line endings (multiple carriage returns without a newline for each carriage return), eclipse gets very confused. that's eclipse issue .

there are two parts to the fix: (1) first, adt was fixed such that it no longer introduces these \r\r sequences into the document. this makes sure that you don't get new documents which triggers the weird editing behavior, but it does not retroactively fix older documents with these line endings, so if you open them, you still get weird editing behavior.

(2) second, there's a new lint check which looks for broken line endings in documents. this runs incrementally, so if you edit an xml file which has this problem, adt will add an error marker for this problem -- along with a quickfix to perform surgery on the document to fix it.

in short: get adt 21 preview 9; run lint on your projects and look for any complaints about files containing broken line endings, and if it finds any, apply the quickfix. from now on, further edits with the layout editor should keep the files consistently formatted.

fyi, the relevant fix is here:

instructions for easily updating sdk tools and the eclipse adt plugin are here:

-- tor (from the android tools team)


i had the same issue. the following steps were the solution. link suggest its worked for others.

  1. go to preferences -> keys
  2. unbind copy, paste, and cut (hit "apply", then "ok")
  3. repeat step 1
  4. restore unbound commands from step 2 (i didn't restore cut, but i'm sure you'd be fine)

notice there are 2 bindings for each of the 3 commands

  1. unbind secondary function for both copy and paste (leave ctl+c/ctl+v [copy/paste] bound)

at this point you should only have 2 bindings set to perform copy/paste (i.e., ctl+c/ctl+v)

  1. hit apply -> ok

this solution was found here.


when this bug appears with new versions of adt (which are mandatory for fixing and where bug should not appear often) just use lint tool to fix it..

find it in lint warnings and click yellow bulb icon in upper right corner of that lint warnings list..

hope it will help somebody


i had the same difficulty and finally found the solution: right click in the editor, select source/cleanup document.


still experiencing this bug on juno (eclipse 4.2.0, adt r20).

my fix: go to window -> preferences -> android -> editors. i have both "format xml using the standard android xml..." and "use eclipse settings for indentation...." checked. this solved the problem for me.


edit: contain faster method, so it was bring to top:

ctrl+f -> fill like that:

  1. "find"          "\r\r\n"
  2. "replace"    "\r\n"
  3. switch "regular expression" to on
  4. hit the "replace all" button
  5. ctrl+a
  6. deselect text.
  7. be happy =)

original was here: just don't hide that issue, if you may fix it. some times even closing the xml file didn't help.

for fix it let's look at the reason of it. first of all turn on "show whitespace characters" (window > preferences > general > editors > text editors > show whitespace characters )

then back to your xml-file.

enter image description here

in scaled image you may see the difference of "\n"-symbol colors;

then just put cursor to that symbol, which is more dark.
enter image description here

look, two lines was selected 0o... that's may be the reason!

so just delete it, and press "enter" or "return" button for add "\n" symbol. enter image description here
hope it help you.

also you may find the other symbol of endline:
enter image description here

just delete it too, and your xml will have a great look!

p.s. sorry for hyperlinks, i'm newbie and on so i can't upload image or more than 2 links. so hope you'll get the point without additional pictures ;)

p.p.s. thx to guy who vote up, now i can provide this with images.


after some tests, i have found that the option "automatically format the xml edited by the visual layout editor" (in preferences | android | editors) might be the culprit here.

with my tests, i've found that changing a property (such as the layout_gravity) while in graphical layout design mode always screw up the visual display of the file when i go back to the xml (text) mode when this option is on but that i have no problem when it's off.

if you want to format the xml upon your return from the graphical layout design mode, simply use the shortcut ctrl+shift+f. also, i didn't see any problem with using the option "format on save"; even when i use it in the graphical layout mode; so you can use ctrl+s instead while you're still in the graphical layout mode to both save and format your xml.

i've tried other editors options like "show range indicator" or "use characters to show changes in vertical ruler" but i didn't see any difference in behavior with activating or de-activating these options.

finally, to correct the visual display of the file when it's corrupt; i found that using the shortcut: ctrl+a, ctrl+c, ctrl+v is a little easier than closing/reopening the file. this is equivalent to making a select all, copy, paste; effectively copying the whole xml file over itself.

Related Query

More Query from same tag