【问题标题】:You must supply a layout_width attribute您必须提供 layout_width 属性
【发布时间】:2014-03-06 00:54:19
【问题描述】:

我有以下 XML 文件正在膨胀,但我不知道为什么会出现错误。这是 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/transitionForm"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/backgroundcolor"
android:orientation="horizontal" >

<include
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    layout="@layout/assistekborders" />

<include
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    layout="@layout/assistek_pro_borderwidgets" />

<include
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    layout="@layout/assistek_pro_questionlabels" />

<include
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    layout="@layout/assistek_pro_practicesessionwidgets" />

<include
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    layout="@layout/assistek_pro_progress" />

<ScrollView
    android:id="@+id/svPRORGWidgets"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/ImageBottom"
    android:layout_below="@+id/lblSubQuestionText"
    android:layout_marginBottom="30px"
    android:layout_marginRight="50px"
    android:layout_marginTop="30px"
    android:layout_toRightOf="@+id/lblQuestionNumber"
    android:descendantFocusability="beforeDescendants" >
    <!-- 
    <TableLayout 
      android:id="@+id/tableLayout1"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
        <TableRow
    android:id="@+id/tableRow1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="5dip" >
     -->
    <RadioGroup
        android:id="@+id/radioGroup"
        android:layout_width="fill_parent"
        android:layout_column="1"
        android:layout_height="wrap_content" >
    </RadioGroup>
     <RadioGroup
        android:id="@+id/radioGroup2"
        android:layout_width="fill_parent"
        android:layout_column="2"
        android:layout_height="wrap_content" >
    </RadioGroup>
    <!-- 
    </TableRow>
    </TableLayout>
     -->
</ScrollView>

这是 logcat 错误。我看不出问题出在哪里 - 我的所有元素都有一个 layout_width 属性。

04-15 21:02:31.800: E/AndroidRuntime(3577): FATAL EXCEPTION: main
04-15 21:02:31.800: E/AndroidRuntime(3577): java.lang.RuntimeException: Unable to start   activity ComponentInfo{com.assistek.ediary/com.assistek.ediary.RadioGroupQuestionnaire}:   java.lang.RuntimeException: Binary XML file line #46: You must supply a layout_width attribute.
04-15 21:02:31.800: E/AndroidRuntime(3577):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
04-15 21:02:31.800: E/AndroidRuntime(3577):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-15 21:02:31.800: E/AndroidRuntime(3577):     at android.app.ActivityThread.access$600(ActivityThread.java:141)

【问题讨论】:

  • 检查所有包含的布局是否在需要时使用android:layout_width 属性正确形成。运行 Android lint 工具来帮助追踪问题。
  • Lint 也找到了 banannn 提供的答案。

标签: android android-layout


【解决方案1】:

ScrollView 只能有一个孩子。

尝试将 RadioGroup 放入 LinearLayout 或 RelativeLayout。

【讨论】:

  • 谢谢 - 这就是问题所在!