Sometimes my code moves on its own or just disappears in the Eclipse XML editor.
When I hi
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
This bug is (finally) fixed in ADT 21. The fix is now available in ADT 21 Preview 9, posted a few minutes ago, here: https://android-review.googlesource.com/#/c/44936/1
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 https://bugs.eclipse.org/bugs/show_bug.cgi?id=375421 .
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: https://android-review.googlesource.com/#/c/44936/
Instructions for easily updating SDK Tools and the Eclipse ADT plugin are here: http://tools.android.com/preview-channel
-- Tor (from the Android tools team)
EDIT: contain faster method, so it was bring to top:
Ctrl+F -> fill like that:
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.
In scaled image you may see the difference of "\n"-symbol colors;
then just put cursor to that symbol, which is more dark.
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.
Hope it help you.
also you may find the other symbol of endline:
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.
I had the same difficulty and finally found the solution: Right click in the editor, select Source/Cleanup Document
.
I had the same issue. The following steps were the solution. Link suggest its worked for others.
Notice there are 2 bindings for each of the 3 commands
At this point you should only have 2 bindings set to perform copy/paste (i.e., ctl+c/ctl+v)
This solution was found here.