Fabricio20
Fabricio20

Reputation: 508

ConstraintLayout Editor Biased

I've been trying to make a GUI for my app (using ConstraintLayout) where I have images that act like buttons aligned, however, those buttons (or anything actually) have this weird issue where even if I move (and save) the constraint position, it just goes back to some number (in this case 16).

What am I doing wrong here? What causes this/Why is the editor resetting the position?

http://i.imgur.com/OFndFb7.gifv (GIF - 40s)

Versions:

XML for the Layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:layout_editor_absoluteY="25dp"
    tools:layout_editor_absoluteX="0dp">

    <Button
        android:id="@+id/Button_Color_Red"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginTop="80dp"
        android:layout_marginStart="16dp"
        android:background="@drawable/btn_red_color_menu"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent" />

    <Button
        android:id="@+id/Button_Color_Indigo"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginTop="80dp"
        android:layout_marginStart="8dp"
        android:background="@drawable/btn_indigo_color_menu"
        app:layout_constraintLeft_toRightOf="@+id/Button_Color_Yellow"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/Button_Color_Green"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginTop="80dp"
        android:layout_marginStart="8dp"
        android:background="@drawable/btn_green_color_menu"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/Button_Color_Indigo"/>

    <Button
        android:id="@+id/Button_Color_Yellow"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginTop="80dp"
        android:layout_marginStart="8dp"
        android:background="@drawable/btn_yellow_color_menu"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/Button_Color_Red" />

</android.support.constraint.ConstraintLayout>

XML for btn_x_color_menu:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/Red_Primary"/>
        </shape>
    </item>
</selector>

Upvotes: 0

Views: 568

Answers (1)

Cheticamp
Cheticamp

Reputation: 62831

There are two attributes on the button Button_Color_Green that are in conflict.

    android:layout_marginLeft="16dp"
    android:layout_marginStart="8dp"

The designer creates android:layout_marginLeft when you move the button, but android:layout_marginStart remains unchanged and in conflict. That is why the margin reverts after you move the widget.

These two attributes should be the same for a left-to-right layout, but the designer seems to want to change android:layout_marginLeft but honors android:layout_marginStart if it is present.

This may be a bug in ConstraintLayout 1.0.2. Until a fix or better solution is found, you can just manually change these attributes to be the same or just use android:layout_marginLeft and manually add android:layout_marginStart back in at a later time. (Lint should remind you to do this.)

Now that you know the issue, you may be able to work out a better solution.

I hope this helps.

Upvotes: 2

Related Questions