【问题标题】:java.lang.RuntimeException: Binary XML file line #0: You must supply a layout_height attributejava.lang.RuntimeException:二进制 XML 文件第 0 行:您必须提供 layout_height 属性
【发布时间】:2018-07-30 11:33:03
【问题描述】:

我该如何解决这个问题?

<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout 
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".Detail_comment"
    >

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="@dimen/heightrvComment">
    </android.support.v7.widget.RecyclerView>

        <include
            layout="@layout/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/heightToolbar"/>


</android.support.constraint.ConstraintLayout>

我找不到我的代码有什么问题。帮帮我。
我想我已经正确放置了所有layout_heightlayout_width

【问题讨论】:

  • You must supply a layout_height attribute - 这里有什么不清楚的地方?
  • 发布您的toolbar.xml 布局。

标签: android android-layout height


【解决方案1】:

layout_heightlayout_width 属性更改为android:... 声明的下方

<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".Detail_comment"android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    >

【讨论】:

    【解决方案2】:

    使用这个

       <?xml version="1.0" encoding="utf-8"?>
      <android.support.constraint.ConstraintLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_height="match_parent"
      android:layout_width="match_parent"
      tools:context=".Detail_comment">
    
      </android.support.constraint.ConstraintLayout>
    

    【讨论】:

      【解决方案3】:

      在开始时移动所有命名空间。 android:layout_height 使用 xmlns:android 命名空间。

      【讨论】:

        【解决方案4】:

        android:layout_height="match_parent"
        android:layout_width="match_parent"
        

        xmlns:android="http://schemas.android.com/apk/res/android" 下方的属性。

        这个概念类似于变量声明。首先,您需要声明属性,然后才能分配它们。

        【讨论】:

          【解决方案5】:

          请在下面输入代码,而不是恒定高度。

            <android.support.v7.widget.RecyclerView
              android:id="@+id/recycler_view"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
          </android.support.v7.widget.RecyclerView>
          

          【讨论】:

            【解决方案6】:

            感谢所有回复。

            我忘记在维度值中写“dp”,所以 android studio 返回那个响应。

            希望,我会更加小心 :D。 谢谢你

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多