在Android Studio预览版中完美展示设计,但在真实设备中却无法实现

在Android Studio预览版中完美展示设计,但在真实设备中却无法实现,android,xml,android-layout,android-studio,android-designer,Android,Xml,Android Layout,Android Studio,Android Designer,我正在开发一个Android应用程序,并试图在Android Studio中实现设计布局 但当我在真实设备上运行它时,它显示的布局就像 在Android Studio中,我使用Nexus 4设计布局,我的手机分辨率为720x1280。 这是我的xml代码 <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="ht

我正在开发一个Android应用程序,并试图在Android Studio中实现设计布局

但当我在真实设备上运行它时,它显示的布局就像

在Android Studio中,我使用Nexus 4设计布局,我的手机分辨率为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>


在设备上运行时,将忽略带有
工具:
前缀的所有属性。你应该用constraintsE.g至少替换所有的
layout\u editor\u absolute
。你能详细说明一下吗,因为我是Android应用程序开发和设计的新手在向布局添加视图后,你必须在design editor中设置所有约束。下面是如何做到这一点的动画。设置所有约束时,应使用类似于“app:layout\u constraintTop\u toTopOf”的内容替换
layout\u editor\u abosult
。尝试使用ConstraintLayout进行设计所需的编码实验室@ziikhankhan?如果不是必需的,那么我建议您使用LinearLayout。实际上,我想设计一个响应性设计,有人告诉我使用约束布局进行响应性设计。它是否兼容所有屏幕(手机和平板电脑)?是的,它兼容所有手机和平板电脑屏幕。您是否尝试过这种设计?在所有设备中?我建议你再检查一遍,然后作为答案填写。是的,我检查过了,我对我的答案有把握。我想你应该检查一下,如果你有任何与此相关的问题,请发送屏幕快照给我,它不起作用<我所做的我突出了粘贴你的代码并从XML更改设备屏幕大小,它与5.0完美结合。事实上,我无法发送简短的评论,这就是为什么我解释你。