【问题标题】:Why is the graphic layout erroring on "android:"为什么“android:”上的图形布局错误
【发布时间】:2013-10-05 19:03:24
【问题描述】:

我刚刚按照 Big Nerd Ranch Android 编程书启动了我的第一个 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: 的任何值?

【问题讨论】:

    标签: android eclipse


    【解决方案1】:

    删除这一行:

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

    【讨论】:

    • 感谢您的帮助,我现在明白问题所在了。
    【解决方案2】:

    您的 xml 命名空间声明中有错字:

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

    应该是

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-18
      • 1970-01-01
      • 2014-12-21
      • 1970-01-01
      • 2012-06-19
      • 1970-01-01
      • 2015-05-25
      • 1970-01-01
      相关资源
      最近更新 更多