When we use Eclipse for Android development, we can import the profile file provided by Google, so that every time "ctrl+shift+f", the IDE will be able to format the code according to the official specifications.
Download
The profile file for Eclipse is in this location on GitHub:
Https://github.com/android/platform_development/tree/master/ide/eclipse
There are two profiles for Java:
- Android.importorder: Used to automatically adjust the order of import statements;
- Android-formatting.xml: Used to format the code.
Attachment Download: Http://files.cnblogs.com/files/duxiuxing/eclipse_android_profile.zip
Import
- Eclipse main Menu Window > Preferences, open Preferences windows;
- Import android-formatting.xml in "Java > Code Style > Formatter";
- Import Android.importorder in Java > Code Style > Organize imports.
Optimization Setup Recommendation 1: Maximum length of comments per line is not qualified
If your project is using Javadoc, it is recommended not to limit the maximum length of comments per line to avoid breaking the layout of the document because of line wrapping.
The setup steps are as follows:
- Open the editor window for profile ' Android ';
- On the comments page, set the maximum line width for comments to 999:
Recommendation 2: Maximum length per line of code is not qualified
The setup steps are as follows:
- Open the editor window for profile ' Android ';
- On the line wrapping page, set the maximum line width to 999:
Formatting Android code in eclipse