皮皮shrimp
皮皮shrimp

Reputation: 35

why do my ConstraintLayout work like this? (things swap position)

the problem's pic (gif)

I am really new to android development, learning from developer.android.com

So stick to the tutorial, I want to make a ConstraintLayout and chain my textbox and button1, but you can see it in that pic. when I'm doing that, they swap position!

I really don't know how to solve that.

Upvotes: 0

Views: 117

Answers (3)

皮皮shrimp
皮皮shrimp

Reputation: 35

select them in component tree! working for me if i select them in "Component Tree" instead of selecting them on blueprint !

Upvotes: 1

Rohan
Rohan

Reputation: 114

try this.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <EditText
        android:id="@+id/emailId"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="36dp"
        android:hint="Enter email ID"
        android:inputType="textEmailAddress"
        app:layout_constraintEnd_toStartOf="@+id/signInBtn"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/signInBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/colorAccent"
        android:text="Sign in"
        android:layout_marginEnd="36dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/emailId"
        app:layout_constraintTop_toTopOf="@id/emailId" />

</androidx.constraintlayout.widget.ConstraintLayout>

enter image description here

Upvotes: 0

siwarak
siwarak

Reputation: 197

You select three view and then "Create horizontal chain" which link view in horizontal only.

Chain will rearrange all view relation to horizontal or vertical.

Read more about constraint chain here


//Solution
If you need to set chain between EditText and Button just pick only both of them.

Upvotes: 0

Related Questions