Max Plakhuta Max Plakhuta - 2 months ago 84
Android Question

Using design support library with constraint layout

I'm tried to use TextInputLayout from support design library within ConstraintLayout, but got a error:

android.widget.LinearLayout$LayoutParams
cannot be cast to android.support.constraint.ConstraintLayout$LayoutParams


How can I achieve the same functionality as support.design.widget.TextInputLayout but with ConstraintLayout?

Full layout is here: http://pastebin.com/TjC0FAdS

Problem is:

<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="match_parent"
android:layout_height="match_parent">
<AutoCompleteTextView
android:layout_width="0dp"
android:layout_height="0dp"
android:singleLine="true"
android:id="@+id/email"
android:hint="@string/prompt_email"
app:layout_constraintLeft_toRightOf="@+id/imageView3"
android:layout_marginStart="8dp"
app:layout_constraintTop_toBottomOf="@+id/logo"
android:layout_marginTop="16dp"
app:layout_constraintRight_toRightOf="@+id/constraintLayout"
android:layout_marginEnd="16dp" />
</android.support.design.widget.TextInputLayout>
</android.support.constraint.ConstraintLayout>

Answer

Attributes such as app:layout_constraintLeft_toRightOf require ConstraintLayout to be a parent view. Move those attributes to the TextInputLayout and it should work fine.