2017-07-02 42 views
0

我剛開始使用android studio,我插入了一個按鈕和文本字段。在預覽面板看起來不錯,但是當我運行應用程序的佈局是不同的。 這是XML代碼:Android工作室在模擬器上的不同佈局

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="16dp" 
android:paddingTop="16dp" 
android:paddingLeft="16dp" 
android:paddingRight="16dp" 

tools:context="com.example.alexander.myapplication.MainActivity"> 


<TextView 
    android:id="@+id/message" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="TextView" 
    tools:ignore="HardcodedText" /> 

<Button 
    android:id="@+id/button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" 
    tools:layout_editor_absoluteX="119dp" 
    tools:layout_editor_absoluteY="222dp" 
    tools:ignore="HardcodedText,MissingConstraints" 
    android:onClick="buttonClicked" 
    /> 

This is how it looks like 謝謝!

回答

0

看行:

tools:layout_editor_absoluteX="119dp" 
tools:layout_editor_absoluteY="222dp" 

什麼,他們說的是,你放置在一個絕對位置,但只有在編輯器中預覽按鈕。 當應用程序實際運行時(注意參數名稱中的「編輯器」前綴),該按鈕沒有真正的放置值。

您需要在編輯器中定義實際值。

退房Android開發者網站上的這個指南: Build a Responsive UI with ConstraintLayout

0

我只是通過設置佈局RelativeLayout的解決了這個問題。

相關問題