Why Android Studio is removing and/or changing layout_margin* constraints? Why Android Studio is removing and/or changing layout_margin* constraints? android android

Why Android Studio is removing and/or changing layout_margin* constraints?


In my case removing the layout constraint and adding it again fixed the disappearing margins.

I'm on Android Studio 4.1.1.


I have been noticing the same issue with Android Studio 2.3, the code changed automatically every time I went from text view to design view on a recent project with ConstraintLayout. - I'm pretty sure it happens with RelativeLayout or whatever other layout you want to use as well.

I guess it is some type of auto code generation bug linked to the design view, I have not been able to find a way to turn it off yet.

I'm not sure this helps because I'm confident you've already realized it, but if you work almost completely in text view, the issue never happens.

I occasionally use design view to begin my layout but once I have something working, staying in text view personally seems to be faster for the development process.


As @JoeyJubb mentioned, using layout_height="match_parent" solves this problem. At least XML is not modified. Although, sometimes preview is generated incorrectly.