我试图在ConstraintLayout中使用来自 support design 库的 TextInputLayout,但是遇到了错误:
android.widget.LinearLayout$LayoutParams
cannot be cast to android.support.constraint.ConstraintLayout$LayoutParams
如何使用ConstraintLayout实现与support.design.widget.TextInputLayout相同的功能?
完整布局如下:http://pastebin.com/TjC0FAdS
问题是:
<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>
TextInputLayout
的代码,并显示崩溃的行。谢谢。 - Gennadii SaprykinConstraintLayout
的经验,所以我不确定。我的猜测是,诸如app:layout_constraintLeft_toRightOf
这样的属性需要将ConstraintLayout
作为父视图。我建议尝试将这三个属性移动到TextInputLayout
标记中,也许那样会起作用。 - Gennadii Saprykin