AS 3.5 Canary 8 以降で、 xml を reformat するとタグ名でソートされてしまう不具合が発生していました。
Android Studio 3.5 Canary 8、layout.xml で Rearrange Code するとタグの順番がタグ名でソートされるんだけど..???
— たかつ (@takasfz) 2019年3月26日
LinearLayout とかでやるとレイアウトが変わる..😂
Android Studio 3.5 Canary 8 で Layout XML を保存したらオートフォーマットでタグがすべて逆順になったんですが、同じ現象の人いますか?ナニコレ
— wada811 (@wada811) 2019年3月26日
AS 3.5 Canary 8からXMLのOrderが変わってソートする度に不便だ
— Pluu (@pluulove) 2019年3月27日
勝手に下のComponentが上に行ってしまう
これについては Issue が発行されており、 AS 3.5 Canary 12 で修正されたようです。
Issue #129323345: Code Formatting changes the order of components in Layout hierarchy
I only overwrite old arrangement rules with the fixed new ones if they're all equal to the old default. If a user has changed them from the default, I don't overwrite them to preserve user customization. For the record, the complete set of fixed new rules look like the following. The only difference is the <XML_ATTRIBUTE /> elements that make them match attributes and not elements.
<XML_ATTRIBUTE />
を追加して、 attribute だけがフォーマットのルールにマッチするようにした。- デフォルトのフォーマットルールを変更していない場合は、この修正が適用される。ルールを変更している場合は、自分で修正を適用する必要がある。
- デフォルトの定義はここにありました ~/Library/Preferences/AndroidStudioPreview3.5/codestyles/Default.xml
とのことなので、デフォルトルールを変更している場合や、プロジェクトでフォーマットルールを共有している場合は、以下の対応を入れましょう。
<section> <rule> <match> <AND> <NAME>xmlns:android</NAME> + <XML_ATTRIBUTE /> <XML_NAMESPACE>.*</XML_NAMESPACE> </AND> </match> </rule> </section> <section> <rule> <match> <AND> <NAME>xmlns:.*</NAME> + <XML_ATTRIBUTE /> <XML_NAMESPACE>.*</XML_NAMESPACE> </AND> </match> <order>BY_NAME</order> </rule> </section> :