Java 约束布局不适合不同的设备

Java 约束布局不适合不同的设备,java,android,xml,android-layout,constraints,Java,Android,Xml,Android Layout,Constraints,我正在尝试调整我用nexus5构建的布局,但它在我的设备上总是有不同的大小,我不知道为什么 我使用约束布局来构建它,正如我所知,约束应该适应不同的设备,但它不起作用;我总是让我的内容更大或与其他内容重叠 以下是我正在构建的布局的xml: 这就是我在模拟器上看到的: 这是我在我的设备上看到的:•在布局XML文件中使用独立于分辨率的单位 •使用布局管理器声明布局,而不参考绝对屏幕位置 •使用多个资源文件夹为不同的屏幕大小提供不同的布局 为确保布局灵活并适应不同的屏幕大小,应使用换行内容并匹配某些视图

我正在尝试调整我用nexus5构建的布局,但它在我的设备上总是有不同的大小,我不知道为什么

我使用约束布局来构建它,正如我所知,约束应该适应不同的设备,但它不起作用;我总是让我的内容更大或与其他内容重叠

以下是我正在构建的布局的xml:

这就是我在模拟器上看到的:


这是我在我的设备上看到的:

•在布局XML文件中使用独立于分辨率的单位

•使用布局管理器声明布局,而不参考绝对屏幕位置


•使用多个资源文件夹为不同的屏幕大小提供不同的布局

为确保布局灵活并适应不同的屏幕大小,应使用换行内容并匹配某些视图组件的宽度和高度 正如我所见,您的图像具有硬代码高度、宽度和边距,可能就是这种情况


尝试改用

,我该怎么做?布局xml文件中的res/values/dimensions.xml为不同的屏幕大小使用不同的布局drawables hdpi,drawables xhdpiyeah但如果我设置为您的意思,图像将变为全尺寸:Syes但我是说将布局从constraintlayout更改为RelativeLayout从您的回答中,您可能会尝试使用constraint layout匹配父级,确切地说,我在所有东西上都使用了约束布局,因为人们说它很适合在不同的屏幕上进行调整,我认为它在开始和结束标记中都自动调整了相对布局,而不是android.support.constraint.ConstraintLayout
<?xml version="1.0" encoding="utf-8"?>
<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="com.example.afcosta.inesctec.pt.android.Login"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="25dp">

    <android.support.design.widget.TextInputLayout
        android:layout_width="0dp"
        android:layout_height="52dp"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintBottom_creator="1"
        app:layout_constraintBottom_toTopOf="@+id/textInputLayout6"
        android:layout_marginStart="45dp"
        android:layout_marginEnd="45dp"
        app:layout_constraintRight_toRightOf="parent"
        tools:layout_constraintLeft_creator="1"
        android:layout_marginBottom="33dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:id="@+id/textInputLayout7">

        <EditText
            android:id="@+id/username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="username" />
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:layout_width="0dp"
        android:layout_height="48dp"
        android:id="@+id/textInputLayout6"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintBottom_creator="1"
        app:layout_constraintBottom_toTopOf="@+id/Login"
        android:layout_marginStart="43dp"
        android:layout_marginEnd="43dp"
        app:layout_constraintRight_toRightOf="parent"
        tools:layout_constraintLeft_creator="1"
        android:layout_marginBottom="42dp"
        app:layout_constraintLeft_toLeftOf="parent">

        <EditText
            android:id="@+id/password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="password"
            android:inputType="textPassword" />
    </android.support.design.widget.TextInputLayout>

    <Button
        android:id="@+id/Login"
        android:layout_width="0dp"
        android:layout_height="48dp"
        android:background="@color/emerald"
        android:text="Entrar"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintBottom_creator="1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="@+id/textInputLayout6"
        tools:layout_constraintLeft_creator="1"
        android:layout_marginBottom="143dp"
        app:layout_constraintLeft_toLeftOf="@+id/textInputLayout6" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Ainda não tem conta?"
        android:layout_marginStart="26dp"
        app:layout_constraintBaseline_toBaselineOf="@+id/textView5"
        tools:layout_constraintBaseline_creator="1"
        tools:layout_constraintLeft_creator="1"
        app:layout_constraintLeft_toLeftOf="@+id/Login" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Registe-se"
        android:textColor="@color/nephritis"
        tools:layout_constraintTop_creator="1"
        android:layout_marginStart="13dp"
        android:layout_marginTop="20dp"
        app:layout_constraintTop_toBottomOf="@+id/Login"
        tools:layout_constraintLeft_creator="1"
        app:layout_constraintLeft_toRightOf="@+id/textView3" />

    <ImageView
        android:id="@+id/imageView8"
        android:layout_width="232dp"
        android:layout_height="230dp"
        app:srcCompat="@drawable/flora"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toTopOf="@+id/textInputLayout7" />
</android.support.constraint.ConstraintLayout>