设计在 Android Studio 预览中完美显示,但在真实设备中不显示

Design Showing Perfectly in Android Studio Preview but Not in Real Device

我正在开发一个 Android 应用程序,我正在尝试在 Android Studio 中实现设计布局,例如 Image in Android Studio Preview

但是当我在真实设备上 运行 它显示的布局类似于 Design In Real Device。

在 Android Studio 中,我使用 Nexus 4 设计布局,我的 Phone 分辨率为 720x1280。 这是我的 xml 代码

<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.usmanali.childsafety.MainActivity">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="275sp"
    tools:ignore="MissingConstraints"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="3dp">

    <ImageView
        android:id="@+id/imgschool"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/im"
        android:contentDescription="@string/todo" />
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="115sp"
    tools:ignore="MissingConstraints"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="278dp">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/download" />
</LinearLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="110sp"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="393dp"
    tools:ignore="MissingConstraints">

    <Button
        android:id="@+id/btnlogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/btnregister"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:text="@string/login"
        android:textStyle="bold"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="291dp" />

    <Button
        android:id="@+id/btnregister"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:text="@string/sign_up"
        android:textStyle="bold"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="340dp" />
</RelativeLayout>

试试这个

<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"
    tools:context=".MainActivity">


    <LinearLayout
        android:id="@+id/mainLinearLayout"
        android:layout_width="match_parent"
        android:layout_height="275sp"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="3dp">

        <ImageView
            android:id="@+id/imgschool"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/im"
            android:contentDescription="@string/todo" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="115sp"
       app:layout_constraintTop_toBottomOf="@+id/mainLinearLayout"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="278dp">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/download" />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="110sp"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="393dp"
        tools:ignore="MissingConstraints">

        <Button
            android:id="@+id/btnlogin"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/btnregister"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:text="@string/login"
            android:textStyle="bold"
            tools:ignore="MissingConstraints"
            tools:layout_editor_absoluteX="0dp"
            tools:layout_editor_absoluteY="291dp" />

        <Button
            android:id="@+id/btnregister"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:text="@string/sign_up"
            android:textStyle="bold"
            tools:ignore="MissingConstraints"
            tools:layout_editor_absoluteX="0dp"
            tools:layout_editor_absoluteY="340dp" />
    </RelativeLayout>
</android.support.constraint.ConstraintLayout>