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.Constraints are a set of rules which determine how an object positions itself relative to other objects and the wider layout. Without constraints, the objects in your app would likely jump out of position when the app is loaded or the device is rotated.
Advantages of using ConstraintLayout in AndroidIt helps to improve the UI performance over other layouts. With the help of ConstraintLayout, we can control the group of widgets through a single line of code. With the help of ConstraintLayout, we can easily add animations to the UI components which we used in our app.
If you have the choice start with ConstraintLayout, but if you already have your app in RelativeLayout, stay with it. That's all I have been following. RelativeLayout is very limited in functionality and many complex layouts can't be made using it, especially when ratios are involved.
android:layout_margin. Specifies extra space on the left, top, right and bottom sides of this view. android:layout_marginBottom.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With