今天运行程序时,出现了这样的错误Unexpected namespace prefix "xmlns" found for tag LinearLayout。原因是因xmlns:android=http://schemas.android.com/apk/res/android这行重复造成的。一般只需要顶层地Layout需要xmlns:android="http://schemas.android.com/apk/res/android" 属性。
其他的Layout去掉该xmlns属性。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="北京" />
<EditText
android:id="@+id/geocodekey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="海淀区上地十街10号" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/geocode"
android:text="CeoCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button android:text="ReverseCeoCode"
android:id="@+id/reversegeocode"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<com.baidu.mapapi.MapView android:id="@+id/bmapView"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:clickable="true"
/>
</LinearLayout>
本文介绍了解决Android布局文件中出现的命名空间重复错误的方法。错误提示为Unexpected namespace prefix xmlns found for tag LinearLayout,主要是由于多个层级的布局元素都包含了相同的xmlns属性。解决方式为仅保留顶层LinearLayout的xmlns属性,并移除其他层级LinearLayout中的相同属性。

1753

被折叠的 条评论
为什么被折叠?



