Все элементы сливаются в левом верхнем углу в макете ограничения, Android Studio

Я новичок, вот как это выглядит, когда я запускаю свое приложение. Я использую последнюю версию студии Android. имея ограничение Layout по умолчанию, вот скриншоты

Это то, что он показывает

https://drive.google.com/file/d/0B-ydaOiOKnYnOG1oODVoZEtwRzA/view?usp=drivesdk

Это то, что я пытаюсь спроектировать

https://drive.google.com/file/d/0B-ydaOiOKnYnQ2NKSXdZencxYk0/view?usp=drivesdk

Помощь была бы ощутимой.


person Ashish    schedule 15.04.2017    source источник
comment
пожалуйста, включите XML, который включает ограничения, которые вы добавили к элементам. если вы не добавили никаких ограничений, поэтому все ваши элементы находятся в левом верхнем углу. Добавьте ограничения, чтобы разместить их правильно.   -  person David Jeske    schedule 15.04.2017


Ответы (1)


Вот чего вы хотите добиться, используя ConstraintLayout

<android.support.constraint.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">

    <TextView
        android:id="@+id/email_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="EMAIL"
        android:textSize="22sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" 
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintVertical_bias="0.2" />

    <EditText
        android:id="@+id/email_input"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_margin="16dp"
        android:background="@android:color/white"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/email_label" />

    <TextView
        android:id="@+id/pwd_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:text="PWD"
        android:textSize="22sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/email_input" />

    <EditText
        android:id="@+id/pwd_input"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_margin="16dp"
        android:background="@android:color/white"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/pwd_label" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="LOGIN"
        android:textSize="16sp"
        android:layout_margin="16dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/pwd_input" />

</android.support.constraint.ConstraintLayout>

В виджете ярлыка электронной почты вы также можете удалить атрибуты «layout_constraintVertical_bias» и «layout_constraintBottom_toBottomOf» и исправить верхнее поле.
Это можно сделать и с помощью цепочек.
Убедитесь, что вы используете ConstraintLayout 1.0.2. .

Вы можете прочитать это замечательное руководство по ConstraintLayout
Создание интерфейсов с помощью ConstraintLayout

Надеюсь это поможет!

person Rami Jemli    schedule 15.04.2017
comment
Спасибо, Рами, это мне очень помогло. - person Ashish; 15.04.2017