android - 您必须提供 layout_height 属性

标签 android xml android-layout debugging xamarin

我已经学习了使用 Xamarin 的教程,但我遇到了一个问题,它一直显示错误:

Android.Views.InflateException: 'Binary XML file line #2: Binary XML file line #2: You must supply a layout_height attribute.'

我已经检查了我的代码很多次了,layout_height 的所有属性都很好。如果还有其他我没有看到的错误,你们能帮忙通知我吗?

这是我要调试的 XML 文件:

<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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/colorchoose"
    android:paddingBottom="10pt"
    android:paddingLeft="10pt"
    android:paddingRight="10pt"
    android:paddingTop="10pt"
    android:hapticFeedbackEnabled="false">
    <ImageView
        android:layout_width="60dp"
        android:layout_height="120dp"
        android:id="@+id/imageView"
        android:layout_marginBottom="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toTopOf="parent"/>
    <TextView
        android:text="LOGIN"
        android:id="@+id/txtlogin"
        android:textColor="#fff"
        android:layout_width="108dp"
        android:layout_height="47dp"
        app:layout_constraintTop_toBottomOf="@id/imageView"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginBottom="8dp"
        android:textSize="20dp"
        android:gravity="center_vertical"
        android:textStyle="bold"
        android:paddingLeft="3dp"/>
    <android.support.design.widget.TextInputLayout
        android:id="@+id/etPasswordLayout"
        android:layout_width="363dp"
        android:layout_height="wrap_content"
        app:passwordToggleEnabled="true"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@id/etPasswordLayout1"
        android:layout_marginBottom="8dp"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp">
        <android.support.design.widget.TextInputEditText
            android:id="@+id/etPassword"
            android:layout_width="match_parent"
            android:textColor="#fff"
            android:hint="Password"
            android:inputType="textPassword"/>
    </android.support.design.widget.TextInputLayout>
    <TextView
        android:text="Forget Password ?    "
        android:layout_width="wrap_content"
        android:textColor="#fff"
        android:layout_height="29dp"
        android:id="@+id/textView2"
        android:layout_marginBottom="8dp"
        app:layout_constraintTop_toBottomOf="@+id/etPasswordLayout"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="20dp"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp"/>
    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:id="@+id/floatingActionButton"
        android:layout_marginTop="170dp"
        app:backgroundTint="#FF007F"
        android:layout_marginBottom="8dp"
        app:layout_constraintTop_toBottomOf="@+id/textView2"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="35dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="50dp"
        app:fabSize="mini"/>
    <Button
        android:text="LOGIN"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button"
        android:textColor="#fff"
        android:background="#ffca"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/textView2"
        android:layout_marginBottom="8dp"/>
    <android.support.design.widget.TextInputLayout
        android:id="@+id/etPasswordLayout1"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        app:layout_constraintTop_toBottomOf="@id/txtlogin"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp">
        <android.support.design.widget.TextInputEditText
            android:id="@+id/etPassword1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="#fff"
            android:hint="Scan PFNo"
            android:inputType="textEmailAddress"/>
    </android.support.design.widget.TextInputLayout>
</android.support.constraint.ConstraintLayout>

这是我的@drawable/colorchoose xml 文件: 它只包含颜色引用

<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <shape>
      <gradient
          android:startColor="#ffff"
          android:endColor="#ffac"
          android:angle="45"/>
    </shape>
  </item>
</selector>

最佳答案

你忘了在这里添加高度:

<android.support.design.widget.TextInputEditText
            android:id="@+id/etPassword"
            android:layout_width="match_parent"
            android:textColor="#fff"
            android:hint="Password"
            android:inputType="textPassword"/>
    </android.support.design.widget.TextInputLayout>

关于android - 您必须提供 layout_height 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58386048/

相关文章:

c# - 在 C# 中重用 xml

java - 在多个 Activity 中重用布局的最简单方法

java - 用一个拇指自定义 rangeseekbar android

android - 从 ViewModel 中的服务器获取数据后,LiveData Observer 不会更新 UI

java - 使用回调对静态方法进行单元测试

java - 解析 XML 时的问题

xml - 我可以使用 VBA 中的变量更新 XML 节点值吗

显示像素化的 Android 抽屉导航项目图标

android - 在 ListView 中使用 RelativeLayout 时 View 的背景颜色被移除

android - 预防多个 Android 设备上的 Firebase 同一帐户