Reputation: 11555
I'm using android.support.constraint.ConstraintLayout
to layout a simple card's content views.
I'm getting random changes in my XML, every time, when:
Design
tabPreview
pane turned on (in this case changes happens even more often during my changes).Those random changes include:
layout_marginEnd
)tools:layout_editor_absoluteX
valuesQuestions:
Please take a look to this file diff, which was made automatically when switched to Design tab:
PS.: My Android Studio version is 2.2.3
; I'm running it on macOS Sierra.
As suggested, after making layout_height="match_parent"
, I get modifications less often, but still my XML gets messed-up, when I edit layout in Layout Design'er:
This time I wanted to set
layout_marginTop
through Design UI (selected line is what I wanted to add), but I also got those other unwanted changes:
layout_marginStart
removed;app:layout_constraintBottom_toBottomOf
referenced IDs got a prefix of "+" sign, which means, those IDs are newly declared, so when I'll use Goto declaration
functionality, I'll have to choose it from the list - not a desired behaviour.tools:layout_editor_absoluteX
gets added. I could ignore it, but still - not what I'd want to happen.Upvotes: 16
Views: 3843
Reputation: 3185
In my case removing the layout constraint and adding it again fixed the disappearing margins.
I'm on Android Studio 4.1.1.
Upvotes: 3
Reputation: 1411
In my case upgrade to newest gradle dependecy helped:
com.android.support.constraint:constraint-layout:1.0.2
Also I started using 0dp
instead of match_parent
for layout_width
Upvotes: 0
Reputation: 2813
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.
Upvotes: 1
Reputation: 11555
As @JoeyJubb mentioned, using layout_height="match_parent"
solves this problem. At least XML is not modified. Although, sometimes preview is generated incorrectly.
Upvotes: 0