XML attributes arrangement in Android Studio

无人久伴 提交于 2021-02-19 05:49:05

问题


I like to arrange my XML files similar to this question

But I'd like to add an ordering like this:

  1. View id
  2. Style
  3. Layout width and layout heigt
  4. Other layout_ attributes, sorted alphabetically
  5. Remaining attributes, sorted alphabetically

Example:

<Button
    android:id="@id/button_accept"
    style="@style/ButtonStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true"
    android:padding="16dp"
    android:text="@string/button_skip_sign_in"
    android:textColor="@color/bluish_gray" />

I had a look at Editor -> Code Style -> XML -> Arrangement, but the only thing I could do was order every attribute alphabetically. This documentation from IntelliJ couldn't help me I'm still not sure what the namespace is supposed to do.

Maybe someone here understands it better? The UI gave me the impression, that the order of the matching rules is, what the order of the attributes should be. But somehow it doesn't change or do anything.


回答1:


I'm feeling stupid now, but I figured out my mistake: name of the attribute in question needs to start with android:.

Result:



来源:https://stackoverflow.com/questions/40089102/xml-attributes-arrangement-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!