- 浏览: 1505856 次
- 性别:
- 来自: 南京
文章分类
- 全部博客 (419)
- XMPP (19)
- Android (180)
- Java (59)
- Network (4)
- HTML5 (13)
- Eclipse (9)
- SCM (23)
- C/C++ (4)
- UML (4)
- Libjingle (15)
- Tools&Softwares (29)
- Linphone (5)
- Linux&UNIX (6)
- Windows (18)
- Google (10)
- MISC (3)
- SIP (6)
- SQLite (5)
- Security (4)
- Opensource (29)
- Online (2)
- 文章 (3)
- MemoryLeak (10)
- Decompile (5)
- Ruby (1)
- Image (1)
- Bat (4)
- TTS&ASR (28)
- Multimedia (1)
- iOS (20)
- Asciiflow - ASCII Flow Diagram Tool.htm (1)
- Networking (1)
- DLNA&UPnP (2)
- Chrome (2)
- CI (1)
- SmartHome (0)
- CloudComputing (1)
- NodeJS (3)
- MachineLearning (2)
最新评论
-
bzhao:
点赞123!
Windows的adb shell中使用vi不乱码方法及AdbPutty -
wahahachuang8:
我觉得这种东西自己开发太麻烦了,就别自己捣鼓了,找个第三方,方 ...
HTML5 WebSocket 技术介绍 -
obehavior:
view.setOnTouchListenerview是什么
[转]android 一直在最前面的浮动窗口效果 -
wutenghua:
[转]android 一直在最前面的浮动窗口效果 -
zee3.lin:
Sorry~~
When I build "call ...
Step by Step about How to Build libjingle 0.4
http://www.androidpolice.com/2009/11/04/auto-formatting-android-xml-files-with-eclipse/
http://envyandroid.com/archives/195/formatting-android-xml-eclipse
The Problem
However, one thing about Eclipse Android development has bothered me for a while - and that is XML formatting by the visual tools. See, if you open an XML file in Eclipse and use the Layout/Resources tab (which functions as either a visual UI builder or a visual frontend to resource management), Eclipse creates the XML representation of what you're building and dumps it into the file you're editing. The problem is, this XML is not formatted in any way - Eclipse just writes it in a single line, which looks absolutely horrible and is essentially unusable.
For example, I had this beautifully formatted XML file with a sample Android menu. After using the Layout tab to add another item, I ended up with an single ugly unindented line for it.
The Solution
Here's how to solve this in an almost fully automated fashion, using formatting rules that I think result in the most readable file. There is no need for external tools - Eclipse provides everything needed.
- open up Window->Preferences->XML->XML Files->Editor
- check the "Split multiple attributes each on a new line" and adjust other options according to your liking (such as Indent using spaces and Indentation size)
- press OK to save the options
- all you have to do now is press Ctrl-Shift-F or select Source->Format
Let's see what this does to the XML I showed above:
It's a beauty, isn't it? Eclipse's Auto Format is one of its best features (yes, you can apply it to your Android Java code too as well as pretty much any other document format).
Bonus - XML Cleanup
As an added bonus, Eclipse also offers a Cleanup XML option, which can do the following:
- compress empty element tags
- insert required attributes
- insert missing tags
- quote attribute values
- format source (as above)
- convert line delimiters to Windows, UNIX, or Mac
You can access the Cleanup option via Source->Cleanup
Running Cleanup on my already pretty clean XML file turned the last <item> into this:
The first option compressed the <item></item> declaration to simply <item />. Neat, isn't it?
Final Words
+ Clean is good.
+ Uniform is good.
+ Use Ctrl-Shift-F and make it a habit.
+ Create a keyboard shortcut to the Cleanup function by going to Window->Preferences->General->Keys and use it instead of Ctrl-Shift-F (since it already formats as part of the Cleanup).
? I'd like to know if there is a way to apply auto formatting upon save, automatically. Do you?
发表评论
-
[Android] 为Android安装BusyBox —— 完整的bash shell
2013-12-27 10:19 1496http://www.cnblogs.com/xiaowen ... -
Windows的adb shell中使用vi不乱码方法及AdbPutty
2013-12-27 10:17 7589http://www.veryhuo.com/down/ht ... -
AppMobi推出新XDK,可创建测试PhoneGap项目
2012-09-03 13:39 2638AppMobi今天发布了一个新的工具PhoneGap Mobi ... -
Sencha
2012-09-03 12:59 1186http://www.sencha.com/ Se ... -
jQuery Mobile学习
2012-09-01 12:33 1692使用Jquery Mobile设计Android通讯录 ... -
BackBone
2012-09-01 12:34 1262Backbone.js 是一种重量级javascript M ... -
jQTouch
2012-08-30 15:57 985A Zepto/jQuery plugin for mobil ... -
SwiFTP
2012-08-30 15:43 1309SwiFTP is a FTP server that run ... -
kWS
2012-08-30 15:41 1200kWS is a lightweight and fast W ... -
jQuery Mobile
2012-08-30 15:07 1031http://jquerymobile.com/ -
PhoneGap
2012-08-30 15:07 1046http://phonegap.com/ -
Android Button background image pressed/highlighted and disabled states without
2012-08-06 12:49 1682http://shikii.net/blog/android- ... -
[AndriodTips]Image, saved to sdcard, doesn't appear in Android's Gallery app
2012-08-04 16:15 1161http://stackoverflow.com/questi ... -
Voice detection for Android
2012-07-23 11:39 2353Here it is, my fist JAVA applic ... -
[AndroidTip]local reference table overflow (max=512)的错误解决
2012-07-22 22:56 6054JNI层coding经常会遇到ReferenceTable o ... -
[AndroidTip]EditText如何初始状态不获得焦点?
2012-07-22 15:35 1227最简单的办法是在EditText前面放置一个看不到的Linea ... -
[AndroidTip]android textview滚动条
2012-07-21 14:29 1300本来是想做一个显示文字信息的,当文字很多时View的高度不能超 ... -
Google公布Android 4.1完整功能
2012-07-16 09:48 3188http://www.android.com/about/je ... -
Android开发:使用AudioTrack播放PCM音频数据【附源码】
2012-07-13 15:20 20877http://www.linuxidc.com/Linux/2 ... -
Android上的行车记录仪
2012-07-11 22:31 2010MyCar Recorder DailyRoads
相关推荐
System.Net.Http.Formatting.xml
Eclipse 中: 配置方法: window->preferences->java->Code style->Formatter中导入android-formatting.xml ...http://www.androidpolice.com/2009/11/04/auto-formatting-android-xml-files-with-eclipse/
- 可选步骤:导入`Android-formatting.xml`和`android.importorder`,分别用于定义代码风格和导入顺序。这些文件通常位于`development/ide/eclipse/`目录下。 - 安装AnyEdit插件(可选),这是一个增强Eclipse功能...
然后,导入`Android-formatting.xml`和`android.importorder`文件,分别用于设置代码格式和导入顺序。最后,安装像AnyEdit这样的Eclipse插件,以增强代码编辑功能。 为了导入源码,确保你已经备份了源码,因为导入...
3. **导入编码规范文件**:将`android-formatting.xml`和`android.importorder`文件导入Eclipse,以保持代码风格的一致性。 - 在`Window > Preferences > Java > Code Style > Formatter`中导入`android-formatting...
为了保持代码风格的一致性,导入`android-formatting.xml`和`android.importorder`文件。前者定义了代码格式化规则,后者规定了import语句的排序。在Eclipse中,可以通过以下路径导入这两份文件: 1. `window -> ...
- **导入格式化和导入顺序配置**:将`android-formatting.xml`和`.importorder`文件导入Eclipse,分别用于设置代码风格和导入顺序。在Eclipse的偏好设置中,通过`Window -> Preferences -> Java -> Code Style`进行...
eclipse开发android,代码标准...1、Preference->Java->Code Style->Formatter->Import->添加android-formatting.xml文件 2、Preference->Java->Code Style->Organize Imports->Import->添加android.importorder文件
在开发Android应用时,遵循统一的代码规范是非常重要的,它能提高代码的...通过导入Google提供的`android.importorder`和`android-formatting.xml`,可以在Eclipse环境中轻松实现这些规范,使得代码更加整洁、专业。
- **导入配置文件**:将`android-formatting.xml`和`android.importorder`文件导入到Eclipse中。 - **配置代码风格**:通过`Window -> Preferences -> Java -> Code Style -> Formatter`菜单导入`android-formatting...
- 将`development/ide/eclipse`目录下的`android-formatting.xml`和`android.importorder`文件导入Eclipse,分别用于设定代码格式和import顺序。 4. **安装插件**(可选): - 可以安装AnyEdit Tools等增强...
1. 源码下载后,找到位于/home/mark/android_src/development/ide/eclipse的目录,这里有几个关键文件,如.android-classpath、.android-importorder和.android-formatting.xml,它们影响Eclipse的代码格式化和导入...
- **样式与转码**:XSLT(Extensible Stylesheet Language Transformations)和XSL-FO(XSL Formatting Objects)等技术用于将XML数据转换成其他格式,如HTML或PDF。 - **查询语言**:XPath和XQuery等语言为处理XML...
1. **准备文件**:首先需要将`development/ide/eclipse/`目录下的`.classpath`文件复制到源代码的根目录下,并导入`android-formatting.xml`和`android.importorder`到Eclipse中。 - `.classpath`:定义了项目的类...
另外,为了使整个团队使用统一的格式化规则,可以将`android.formatting.xml`文件分发给团队成员。这个文件包含了你刚才配置的所有格式化规则。团队成员只需将此文件复制到他们的Eclipse安装目录下的`plugins/...
- **Editing and Formatting**: Techniques for editing and formatting source code efficiently using Eclipse's built-in tools. - **Code Navigation**: Features that help navigate through large codebases, ...
Eclipse Tidy - Cleanup HTML/XML Files - **Eclipse Tidy**:清理 HTML/XML 文件的工具。 **下载地址**:[http://eclipsetidy.sourceforge.net/](http://eclipsetidy.sourceforge.net/) #### 20. Checkclipse - ...
首先,将MTK源码目录下的'alps\development\ide\eclipse'中的.classpath、android.importorder和android-formatting.xml文件复制到alps根目录。这些文件将帮助Eclipse正确地识别和格式化Android项目。接着,在...
之前用Eclipse时,格式化XML代码,也会把顺序格式化,这样比较方便,看起来也清晰明了。 比如: 用Eclipse格式化时,会变成: Android Studio解决办法: File > Settings > Code Style > XML > Set from > ...