Android studio在模拟器上的不同布局

Android studio在模拟器上的不同布局,android,xml,layout,Android,Xml,Layout,我刚开始使用android studio,并插入了一个按钮和文本字段。在预览面板看起来不错,但当我运行应用程序的布局是不同的。 这是xml代码: <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:

我刚开始使用android studio,并插入了一个按钮和文本字段。在预览面板看起来不错,但当我运行应用程序的布局是不同的。 这是xml代码:

<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"
    />

谢谢大家!

看下面几行:

tools:layout_editor_absoluteX="119dp"
tools:layout_editor_absoluteY="222dp"
他们说的是,您将按钮放置在绝对位置,但仅在编辑器预览中。 当应用程序实际运行时,按钮没有实际的位置值(请注意参数名称中的“编辑器”前缀)

您需要在编辑器中定义实际值

在Android开发者网站上查看本指南:

我刚刚通过将布局设置为RelativeLayout解决了这个问题