0

我的问题是TextInputEditText视图不会像我期望的那样扩展以占据父级的整个宽度android:layout_width="match_parent"。下面的代码是应用程序的一个片段:

<?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"
    android:id="@+id/constraintLayout">
    <android.support.design.widget.TextInputLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/textInputLayout1"
        android:layout_marginTop="16dp"
        app:layout_constraintTop_toTopOf="@+id/constraintLayout"
        android:layout_marginStart="16dp"
        app:layout_constraintLeft_toLeftOf="@+id/constraintLayout"
        android:layout_marginLeft="16dp"
        app:layout_constraintRight_toLeftOf="@+id/guideline3"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp">
        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/textInputEditText1"/>
    </android.support.design.widget.TextInputLayout>
    <android.support.design.widget.TextInputLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/textInputLayout2"
        android:layout_marginStart="16dp"
        app:layout_constraintLeft_toRightOf="@+id/textInputLayout1"
        android:layout_marginLeft="16dp"
        android:layout_marginEnd="16dp"
        app:layout_constraintRight_toRightOf="@+id/constraintLayout"
        android:layout_marginRight="16dp"
        app:layout_constraintTop_toTopOf="@+id/textInputLayout1"
        app:layout_constraintBottom_toBottomOf="@+id/textInputLayout1">

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/textInputEditText2"
            android:layout_weight="1"
            tools:layout_editor_absoluteY="0dp"
            tools:layout_editor_absoluteX="0dp"/>
    </android.support.design.widget.TextInputLayout>

    <android.support.constraint.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/guideline3"
        app:layout_constraintGuide_Percent="51"
        android:orientation="vertical"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="216dp"/>

</android.support.constraint.ConstraintLayout>
4

2 回答 2

1

将 TextInputLayout 元素的宽度设置为 match_parent

于 2016-08-08T10:02:11.490 回答
1

您的代码非常好,但您可能使用的是旧版本ConstraintLayout(例如 alpha 4)。尝试更新到最新的 alpha 6,这将解决您的问题(您还需要替换app:layout_constraintGuide_Percent="51"app:layout_constraintGuide_percent="0.5"API 更改)

于 2016-08-09T21:34:42.503 回答