Android TextInputLayout在ConstraintLayout中工作不正常

Android TextInputLayout在ConstraintLayout中工作不正常,android,android-textinputlayout,android-constraintlayout,Android,Android Textinputlayout,Android Constraintlayout,我是新来的。我试图将TextInputLayout宽度设置为与父级匹配,但它总是跳转到365dp。我无法将另一个页面底部的TextInputLayout对齐。请帮我解决这个问题。 试试这个 <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"

我是新来的。我试图将TextInputLayout宽度设置为与父级匹配,但它总是跳转到365dp。我无法将另一个页面底部的TextInputLayout对齐。请帮我解决这个问题。


试试这个

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="81dp"
    android:id="@+id/constraint">


    <android.support.design.widget.TextInputLayout
        android:id="@+id/textInputLayout1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="32dp"
        android:layout_marginLeft="32dp"
        android:layout_marginRight="32dp"
        android:layout_marginStart="32dp"
        android:layout_marginTop="32dp"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent">

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

    <android.support.design.widget.TextInputLayout
        android:id="@+id/textInputLayout2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/textInputLayout1"
        app:layout_constraintLeft_toLeftOf="@+id/textInputLayout1"
        app:layout_constraintRight_toRightOf="@+id/textInputLayout1">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="hint" />
    </android.support.design.widget.TextInputLayout>
</android.support.constraint.ConstraintLayout>

如果您想要文本输入版面宽度匹配\u父项,您应该设置
android:layout\u width=“0dp”
并删除所有marginart和marginEnd(或marginLeft和marginRight)



Sarkar您找到解决方案了吗?这是错误的。你永远不应该使用ConstraintLayout的
match\u parent
。我不认为这是真的。如果你想让它占据整个屏幕怎么办?@MartyMiller谢谢你指出我的错误。我已经更新了我的答案,我想你是在混合观点组。属性width/height存在,因此小部件可以通知其父部件它需要多少空间;父级是否能够适应这一点,在onMeasure+onLayout之后需要解决的是另一个问题……因此ConstraintLayout不支持小部件告诉它需要匹配父级;然而,他们可以说他们想要匹配他们的约束(
0dp
),然后让算法决定有多少可用空间;但是,如果父级本身不是CL,CL可以告诉它的父级它想
匹配\u parent
!我对DialogFragment有这个问题。这个解决方案对我有效。谢谢
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="81dp"
    android:id="@+id/constraint">


    <android.support.design.widget.TextInputLayout
        android:id="@+id/textInputLayout1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="32dp"
        android:layout_marginLeft="32dp"
        android:layout_marginRight="32dp"
        android:layout_marginStart="32dp"
        android:layout_marginTop="32dp"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent">

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

    <android.support.design.widget.TextInputLayout
        android:id="@+id/textInputLayout2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/textInputLayout1"
        app:layout_constraintLeft_toLeftOf="@+id/textInputLayout1"
        app:layout_constraintRight_toRightOf="@+id/textInputLayout1">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="hint" />
    </android.support.design.widget.TextInputLayout>
</android.support.constraint.ConstraintLayout>
<android.support.design.widget.TextInputLayout
    android:id="@+id/textInputLayout"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    >
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="hint"
        />
</android.support.design.widget.TextInputLayout>