2017-07-03 104 views
0

在預覽中我讓我的app看起來像這樣。從預覽如何在Android studio中選擇位置文本和按鈕?

圖片:

[1]

不幸的是,當我啓動應用程序的樣子從測試

[2]

畫面和我的網頁代碼

<android.support.constraint.ConstraintLayout 
    android:layout_width="315dp" 
    android:layout_height="66dp" 
    tools:layout_editor_absoluteX="48dp" 
    tools:layout_editor_absoluteY="287dp"> 

</android.support.constraint.ConstraintLayout> 

<android.support.constraint.ConstraintLayout 
    android:layout_width="212dp" 
    android:layout_height="36dp" 
    tools:layout_editor_absoluteX="70dp" 
    tools:layout_editor_absoluteY="232dp"> 

</android.support.constraint.ConstraintLayout> 

<android.support.constraint.ConstraintLayout 
    android:layout_width="271dp" 
    android:layout_height="66dp" 
    tools:layout_editor_absoluteX="70dp" 
    tools:layout_editor_absoluteY="153dp"> 

</android.support.constraint.ConstraintLayout> 

<android.support.constraint.ConstraintLayout 
    android:layout_width="218dp" 
    android:layout_height="51dp" 
    tools:layout_editor_absoluteX="2dp" 
    tools:layout_editor_absoluteY="4dp"> 

</android.support.constraint.ConstraintLayout> 

<android.support.constraint.ConstraintLayout 
    android:layout_width="271dp" 
    android:layout_height="66dp" 
    tools:layout_editor_absoluteX="70dp" 
    tools:layout_editor_absoluteY="77dp"> 

</android.support.constraint.ConstraintLayout> 

<TextView 
    android:id="@+id/textView8" 
    android:layout_width="218dp" 
    android:layout_height="51dp" 
    android:text="Se connecter" 
    android:textSize="30sp" 
    android:textStyle="bold" 
    tools:layout_editor_absoluteX="2dp" 
    tools:layout_editor_absoluteY="4dp" /> 

<EditText 
    android:id="@+id/editText2" 
    android:layout_width="270dp" 
    android:layout_height="67dp" 
    android:ems="10" 
    android:hint="Numero de telephone" 
    android:inputType="phone" 
    tools:layout_editor_absoluteX="70dp" 
    tools:layout_editor_absoluteY="77dp" /> 

<EditText 
    android:id="@+id/editText3" 
    android:layout_width="274dp" 
    android:layout_height="66dp" 
    android:ems="10" 
    android:hint="Mot de pass" 
    android:inputType="textPassword" 
    tools:layout_editor_absoluteX="70dp" 
    tools:layout_editor_absoluteY="153dp" /> 

<CheckBox 
    android:id="@+id/checkBox6" 
    android:layout_width="214dp" 
    android:layout_height="36dp" 
    android:text="rester connecte" 
    tools:layout_editor_absoluteX="70dp" 
    tools:layout_editor_absoluteY="232dp" /> 

<Button 
    android:id="@+id/button3" 
    android:layout_width="313dp" 
    android:layout_height="64dp" 
    android:text="Se connecter" 
    tools:layout_editor_absoluteX="48dp" 
    tools:layout_editor_absoluteY="287dp" /> 

+0

爲什麼不直接使用Android Studio中的設計選項卡,以創建佈局? – gommb

+0

是的,我確實使用了設計選項卡,但是當我啓動應用程序時,它看起來很糟糕 –

+0

從代碼看,您似乎沒有使用佈局。嘗試使用相對佈局並將所有元素放置在其中。 – gommb

回答

0

當您使用ConstraintLayout你必須元素之間添加約束。當您只需使用佈局編輯器拖放它們時,它只會創建僅在android studio中使用的鍵"tools:layout_editor_absoluteX""tools:layout_editor_absoluteY",因此它知道如何在佈局編輯器中顯示它們。

你可以按照這個鏈接,瞭解如何使用ConstraintLayout https://developer.android.com/training/constraint-layout/index.html

相關問題