Android Studio reorders view elements in layout xml when formatting

Issue

I clean installed Android Studio, currently running Build #AI-213.7172.25.2113.9014738, built on August 31, 2022. Inside layout XMLs When hitting CTRL+ALT+L to format, or also when having the format-option checked in the commit-prompt before committing my changes to git, the IDE will reorder the View elements in my XMLs.

Since the order of View elements determines which View is drawn on top of the others, this causes issues. How do i disable this behaviour? I looked at the CodeStyle settings for XMLs but couldn’t find any settings for this specific behaviour.

Solution

Under Settings -> Editor -> Code Style -> XML there is the option "Set from…" on the top right corner. If that isn’t set to "Android", this could be the problem.

Answered By – Lucas.K

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published