TheKingOfAtlantis TheKingOfAtlantis - 3 months ago 26
Android Question

TextInputEditText view not rendering as expected

My problem is that

TextInputEditText
view does not expand to take up the entire width of the parent as I expect from using
android:layout_width="match_parent"
.
The code below is a snippet from the application:

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

Answer

Your code is perfectly fine, but you likely are using an older version of ConstraintLayout (e.g. alpha 4). Try updating to the latest alpha 6, this will fix your issue (you will also need to replace app:layout_constraintGuide_Percent="51" by app:layout_constraintGuide_percent="0.5" as there was an API change)