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