【问题标题】:error: Error parsing XML: unbound prefix after adding ScrollView错误:解析 XML 时出错:添加 ScrollView 后未绑定前缀
【发布时间】:2014-03-22 18:33:04
【问题描述】:

将滚动视图添加到我的 xml 文件后,我在第 4 行出现错误。 我尝试移动 xmlns:android="http://schemas.android.com/apk/res/android",但仍然遇到同样的错误。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<RelativeLayout
android:id="@+id/RelativeLayout01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.easy.convert.MainActivity" >

<ImageButton
    android:id="@+id/btnbitsbytes"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="25dp"
    android:background="#00000000"
    android:gravity="center"
    android:src="@drawable/btnbitsbytes" />

<ImageButton
    android:id="@+id/btnmassweight"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/btnbitsbytes"
    android:layout_below="@+id/btnbitsbytes"
    android:layout_marginTop="14dp"
    android:background="#00000000"
    android:src="@drawable/btnmassweight" />

<ImageButton
    android:id="@+id/ButtonConvert"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/btnmassweight"
    android:layout_below="@+id/btnmassweight"
    android:layout_marginTop="14dp"
    android:background="#00000000"
    android:src="@drawable/btnlength" />

<ImageButton
    android:id="@+id/imageButton3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/ButtonConvert"
    android:layout_below="@+id/ButtonConvert"
    android:layout_marginTop="14dp"
    android:background="#00000000"
    android:src="@drawable/btntemperature" />

<ImageButton
    android:id="@+id/imageButton4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/imageButton3"
    android:layout_below="@+id/imageButton3"
    android:layout_marginTop="15dp"
    android:background="#00000000"
    android:src="@drawable/btndistance" />

<ImageButton
    android:id="@+id/imageButton5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageButton4"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="22dp"
    android:background="#00000000"
    android:src="@drawable/btnaboutus" />

</RelativeLayout>
</ScrollView>

【问题讨论】:

  • 从您的RelativeLayout 中删除xmlns 行并尝试。
  • Duplicate xmlns:android 是一个错误,但它会产生另一个错误消息。如果删除它没有帮助,请考虑发布更多 XML。
  • 这并不能解决问题,但这是另一个观察结果:"fill_parent" 自 API 级别 8(包括在内)以来已被弃用。请改用"match_parent"

标签: android xml parsing scrollview prefix


【解决方案1】:

RelativeLayout 删除xmlns:android="http://schemas.android.com/apk/res/android"。这只需要根元素,即ScrollView

<RelativeLayout
android:id="@+id/RelativeLayout01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
>

删除这个

tools:context="com.easy.convert.MainActivity"

或添加xmlns:tools="http://schemas.android.com/tools"

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:id="@+id/ScrollView01"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" 
 tools:context="com.easy.convert.MainActivity">

编辑:

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

是 android 的 xml 命名空间。

 xmlns:tools="http://schemas.android.com/tools"

http://schemas.android.com/tools 是命名空间 uri,前缀是 tools。您可以找到工具属性列表@

http://tools.android.com/tech-docs/tools-attributes

【讨论】:

  • @Tanmay 发布整个 xml
  • @Tanmay 删除此tools:context="com.easy.convert.MainActivity"
  • 我没有删除这一行,而是添加了 xmlns:tools="schemas.android.com/tools" 行。你能告诉我 tools:context 有什么用吗?
  • @Tanmay 你可以这样做
  • 非常感谢拉古南丹! :)
【解决方案2】:

你有tools:context="com.easy.convert.MainActivity" 属性。您还需要声明 tools 命名空间前缀,例如声明 android

xmlns:tools="http://schemas.android.com/tools"

【讨论】:

  • 非常感谢@laalto!
猜你喜欢
  • 1970-01-01
  • 2015-05-09
  • 1970-01-01
  • 2015-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-07
  • 2012-12-22
相关资源
最近更新 更多