我们用Eclipse做Android开发的时候,可以导入Google提供的profile文件,这样每次“Ctrl+Shift+F”的时候,IDE就能够按照官方的规范来进行代码格式化。
 下载
 Eclipse用的profile文件在GitHub上的这个位置:
  https://github.com/android/platform_development/tree/master/ide/eclipse
 Java用的profile文件有两个:
  - android.importorder:用来自动调整import语句的顺序;  
 - android-formatting.xml:用来格式化代码。
 
 附件下载:http://files.cnblogs.com/files/duxiuxing/eclipse_android_profile.zip
 导入
  - Eclipse主菜单Window > Preferences,打开Preferences窗口;  
 - 在“Java > Code Style > Formatter ”中导入android-formatting.xml;  
 - 在“Java > Code Style > Organize Imports ”中导入android.importorder。
 
 
 优化设置
 建议1:不限定每行注释的最大长度
 如果项目有在使用Javadoc,建议不要限定每行注释的最大长度,以免因为自动换行而破坏文档的排版。
 设置步骤如下:
  - 打开Profile‘Android’的编辑窗口;  
 - 在Comments页,把Maximum line width for comments设置成999:

 
  建议2:不限定每行代码的最大长度
 设置步骤如下:
  - 打开Profile‘Android’的编辑窗口;  
 - 在Line Wrapping页,把Maximum line width设置成999:
  
在Eclipse中格式化Android代码
原文:http://www.cnblogs.com/duxiuxing/p/6012383.html