3

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>
Max Plakhuta
  • 310
  • 2
  • 14
  • Please share the code where you use `TextInputLayout` showing the line where it crashes. Thank you. – Gennadii Saprykin Jun 21 '16 at 15:39
  • @GennadiiSaprykin, I added my layout. It's crashing while onCreate trying to inflate layout. – Max Plakhuta Jun 21 '16 at 15:51
  • Unfortunately I don't have an experience with `ConstraintLayout` so I'm not sure. My guess is that attributes such as `app:layout_constraintLeft_toRightOf` require `ConstraintLayout` to be a parent view. I would try moving those three attributes to the `TextInputLayout` tag, maybe that will work. – Gennadii Saprykin Jun 21 '16 at 16:02
  • @GennadiiSaprykin, that was excellent idea! Moving those attributes to `TextInputLayout` made it work. Can you answer my question so I accept it? – Max Plakhuta Jun 21 '16 at 16:18
  • oh that's great, glad to hear. Posted my answer. Thank you. – Gennadii Saprykin Jun 21 '16 at 16:23

2 Answers2

5

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.

Gennadii Saprykin
  • 4,505
  • 8
  • 31
  • 41
0

In my experience, reading the Android documentation is a good first step. Emulators work well but you really want to get comfortable with the design patterns and interactions from an OS level.

If you or your company have test devices I would suggest using an Android phone for a few weeks. I used Android for everything excepts calls/texts. You'll start to pick up on subtle differences between iOS and Android. ex: Use of UIAlerts vs Toasts vs Dialogs

--

For resources check out: google.com/design/spec & http://blog.mengto.com/how-to-design-for-android-devices/ and Medium articles.

Documentation for Android is ok but the best way to learn is to pair with a designer who has designed for Android before. Even if it's just to learn the differences between iOS and Android you'll learn a bunch.