我在android视图中经常出现问题,错误解析XML:第2行未绑定前缀。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical" android:id="@+id/myScrollLayout" 
android:layout_width="fill_parent"  android:layout_height="wrap_content">
    <TextView android:layout_height="wrap_content" android:layout_width="fill_parent" 
    android:text="Family" android:id="@+id/Family" 
    android:textSize="16px" android:padding="5px" 
    android:textStyle="bold" android:gravity="center_horizontal">
    </TextView>

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:orientation="vertical" android:scrollbars="vertical">
        <LinearLayout android:orientation="vertical" android:id="@+id/myMainLayout" 
        android:layout_width="fill_parent"  android:layout_height="wrap_content">
        </LinearLayout>
    </ScrollView>

</LinearLayout>

当前回答

您只需要在根标记中添加适当的名称空间。 xmlns: android = " http://schemas.android.com/apk/res/android " Android元素是在这个名称空间中声明的。它与导入类或包相同。

其他回答

对我来说,我在第一行得到了“unbound prefix”错误,尽管我在第四行拼错了android。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
anrdoid:fillViewport="true"
>

您只需要在根标记中添加适当的名称空间。 xmlns: android = " http://schemas.android.com/apk/res/android " Android元素是在这个名称空间中声明的。它与导入类或包相同。

我遇到了同样的问题,发现解决方案是在第一个节点上添加android:tools。在我的例子中,它是一个LineraLayout:

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

我在使用Xamarin时出现了这个错误

  <android.support.v7.widget.CardView  
    android:layout_width="match_parent"  
    android:layout_height="wrap_content"  
    card_view:cardElevation="4dp"  
    card_view:cardCornerRadius="5dp"  
    card_view:cardUseCompatPadding="true">  
  </android.support.v7.widget.CardView>

在布局文件中,不安装nuget包

安装适用的nuget包解决了这个问题。希望有帮助,我在列表中没有看到这个答案

我要加一个单独的答案,因为我在这里没有看到。这不是Pentium10所要求的100%,但我在这里搜索了“错误解析XML:未绑定前缀”

事实证明,我为AdMob广告使用了自定义参数,如ads:adSize,但我还没有添加

    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

对布局。一旦我添加它,它工作得很好。