为什么“android:”上的图形布局错误

时间:2013-10-05 19:03:25

标签: android eclipse

我刚刚开始我的第一个Android应用程序跟随Big Nerd Ranch Android编程书并且在第一个练习中让我输入以下XML:

<LinearLayout xmlns:android="http://schema.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:gravity="center"
  android:orientation="vertical">

  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="24dp"
    android:text="@string/question_text"
  />

  <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/true_button"
    />

    <Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/false_button"
    />
  </LinearLayout>
</LinearLayout>

然而,当我切换回图形视图时,它给了我一堆错误,如:

"<LinearLayout>" does not set the required layout_width attribute:
   (1) Set to "wrap_content"
   (2) Set to "match_parent"

当我点击将其设置为一个或另一个时,它将我的XML更改为:

<LinearLayout xmlns:android="http://schema.android.com/apk/res/android"
  xmlns:android1="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android1:layout_width="match_parent"
  android:layout_height="match_parent"
  android1:layout_height="match_parent"
  android:gravity="center"
  android:orientation="vertical" >

为什么我坚持使用android1:而不接受android:任何值?

2 个答案:

答案 0 :(得分:2)

删除此行:

  xmlns:android1="http://schemas.android.com/apk/res/android"

答案 1 :(得分:1)

你的xml命名空间声明中有一个拼写错误:

xmlns:android="http://schema.android.com/apk/res/android"

应该是

xmlns:android="http://schemas.android.com/apk/res/android"