0

我是初学者,这是它运行我的应用程序时的样子。我正在使用最新版本的Android工作室。有约束布局为默认这里是截图所有项目合并到约束布局的左上角,Android Studio

这就是它显示

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

这是林试图设计

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

帮助将是明显的。

+0

请包括XML,其中包含您添加到元素中的约束。如果你没有添加任何约束,那就是为什么你的元素都在左上角。添加约束来正确放置它们。 –

回答

4

这里是你想用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
Building interfaces with ConstraintLayout

希望这有助于!

+0

谢谢拉米它帮了我很多。 – Ashish