All items merges to top left in constraint Layout , Android Studio [duplicate]

余生长醉 提交于 2021-02-07 10:55:19

问题


I am a beginner this is what it looks when i run my app . i am using latest version of Android studio. having constraint Layout as default here are the screenshots

This is what it shows

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

This is what im trying to design

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

Help would be appreciable.


回答1:


Here's what you want to achieve using 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>

In the email label's widget, You can also remove the "layout_constraintVertical_bias" and "layout_constraintBottom_toBottomOf" attributes and fix a top margin.
This can be done using Chains too.
Make sure you are using ConstraintLayout 1.0.2.

You can read this great tutorial about ConstraintLayout
Building interfaces with ConstraintLayout

Hope this helps!



来源:https://stackoverflow.com/questions/43422887/all-items-merges-to-top-left-in-constraint-layout-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!