我已经在Android应用中为“自定义小部件”制作了一个xml文件,错误是:


解析XML时出错:未绑定前缀


这是我的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.example.CustomWidget.MyView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"

        android:id="@+id/surface"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:layout_weight="1"/>

</LinearLayout>


com.example.CustomWidget是我的包的名称,MyView是我创建自定义Widget的类文件的名称。

最佳答案

第二个XML名称空间是正确的,但是它是自定义窗口小部件的名称空间,因此您需要适当地定义名称空间:

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


变成:

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


此后,您为自定义视图定义的任何自定义属性元素将被称为:

mynamespace:my_defined_attribute="success"


代替 :

android:layout_width="fill_parent"

10-07 19:20
查看更多