我是ConstraintLayout的新手。我试图设置TextInputLayout宽度以匹配父级,但是它总是跳到365dp。而且我无法将TextInputLayout对齐到另一个底部。请帮我解决这个问题。
Screenshot

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayoutxmlns: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="dcastalia.com.cook4me.LoginActivity"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">


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

    <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:layout_width="395dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    app:layout_constraintTop_toBottomOf="@+id/textInputLayout"
    app:layout_constraintRight_toRightOf="@+id/textInputLayout">

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

最佳答案

如果您希望TextInputLayout的宽度为match_parent,则应设置android:layout_width="0dp"并删除所有marginStart和marginEnd(或marginLeft和marginRight)

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

关于android - TextInputLayout在ConstraintLayout中无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43169003/

10-12 04:47