XML属性以便在Android的工作室 [英] XML attributes order in Android Studio

查看:222
本文介绍了XML属性以便在Android的工作室的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在面临的问题,在保持Android的工作室XML属性的正确顺序。正如你可以看到下面的风格属性布局之间_ * 属性,但我想它的名字订购(如在Eclipse)。我使用的是标准的IntelliJ code格式和Android Studio为用户设置自己的有关XML排序规则的能力。该设置位于 code类 - > XML - >安排,但它似乎不工作或我使用它错了。任何想法如何使用默认的code格式化命令用名称的XML属性?

 < TestView的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    风格=@风格/ BackgroundLight
    机器人:layout_height =WRAP_CONTENT>

< / TestView>
 

解决方案

终于明白了。

  1. 选择文件>设置> code样式和GT; XML>设定从> predefined样式和GT;安卓
  2. 设置文件>设置>编辑>格式化和GT;显示格式化code对话框
  3. 运行在一个XML文件格式( Ctrl + Alt + L 默认情况下)
  4. 您将会看到一个弹出窗口,设置重新排列项标志
  5. 禁用格式化code 在设置对话框

这样每个XML文件格式将设置属性以正确的顺序。

编辑: 与Android Studio的0.2.6版本开始的XML Android的风格格式是默认设置,但你还是要手动设置重新排列条目标志。

<一个href="http://tools.android.com/recent/androidstudio026released">http://tools.android.com/recent/androidstudio026released

  

自动应用的Andr​​oid XML code风格的,如果code风格有没有   已经定制。这将使得能够自动   为了XML属性(签入了重新排列项复选框   code>格式化code ...对话框。)

I'm facing problem with keeping proper order of XML attributes in Android Studio. As you can see below, the style attribute is between layout_* attributes, but I want it to be ordered by name (like in Eclipse). I'm using standard Intellij code formatter and the Android Studio gives users ability to set your own rules regarding XML ordering. The settings are located in Code Style -> XML -> Arrangement, but it seems not to work or I'm using it wrong. Any ideas how to order XML attributes by name using default code formatter?

<TestView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    style="@style/BackgroundLight"
    android:layout_height="wrap_content">

</TestView>

解决方案

Finally got it.

  1. Choose File > Settings > Code Style > XML > Set from > Predefined Style > Android
  2. Set File > Settings > Editor > Formatting > Show "Reformat Code" dialog
  3. Run formatting on a XML file (CTRL+ALT+L by default)
  4. You will see a popup window, set the Rearrange entries flag
  5. Disable Reformat Code dialog in the settings

This way every XML file formatting will set the attributes in a proper order.

Edit: Starting with Android Studio 0.2.6 release the XML Android style formatting is set by default, but you still have to set the Rearrange Entries flag manually.

http://tools.android.com/recent/androidstudio026released

Automatically apply the Android XML code style if a code style hasn't already been customized. This will make it possible to automatically order XML attributes (check the "Rearrange Entries" checkbox in the "Code > Reformat Code..." dialog.)

这篇关于XML属性以便在Android的工作室的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆