【问题标题】:"Binary XML file line #8: You must supply a layout_width attribute" Although Attributes Already Exist“二进制 XML 文件第 8 行:您必须提供 layout_width 属性”虽然属性已经存在
【发布时间】:2013-12-03 13:00:51
【问题描述】:

我收到一条错误提示

 "Binary XML file line #8: You must supply a layout_width attribute."

但是我已经指定了布局宽度 (fill_parent),所以我真的不确定为什么会这样。我敢肯定这是我忽略的一些简单的事情——我只是不确定那可能是什么。

来源:


<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <RelativeLayout>

        <View
            android:layout_width="1dp"
            android:layout_height="5dp" >
        </View>

        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" >

            <com.google.android.youtube.player.YouTubePlayerView
                android:id="@+id/youtubeplayerview"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />

            <View
                android:layout_width="1dp"
                android:layout_height="5dp" >
            </View>

            <TextView
                android:id="@+id/textView1a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Isaac Daniel at CNN Anderson Cooper"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView2a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="by idconex"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="675,000,000 views"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <com.google.android.youtube.player.YouTubePlayerView
                android:id="@+id/youtubeplayerview2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/textView1b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Rage Against The Machine - Bulls on Parade"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView2b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="by RATMVEVO"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1,195,601 views"
                android:textAppearance="?android:attr/textAppearanceSmall" />
        </ScrollView>
    </RelativeLayout>

</LinearLayout>

【问题讨论】:

  • 你没有为你的&lt;RelativeLayout&gt;指定任何东西
  • I already have a layout width specified (fill_parent) 不,你没有。 &lt;RelativeLayout&gt; 没有 layout_width。
  • 我很困惑。该错误告诉您要搜索什么以及在哪里寻找它。你怎么能错过呢?

标签: java android xml android-layout android-relativelayout


【解决方案1】:

您的RelativeLayout 没有宽度和高度。试试这个:

<RelativeLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent">

【讨论】:

  • 导致Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child
  • 这完全是另一个错误,问题是,您的 ScrollView 中有多个元素。 ScrollView 只能容纳一个 View,如果你想添加更多你必须把它们放在一个 ViewGroup 中(也许一个 LinearLayout 可以解决你的问题)。
【解决方案2】:

你应该给布局高度和宽度

使用这个

<RelativeLayout
         android:id="@+id/relativeLayout"
         android:layout_width="match_parent"
         android:layout_height="match_parent">

【讨论】:

    猜你喜欢
    • 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
    相关资源
    最近更新 更多