gpt4 book ai didi

android-layout - 解析 XML 时,未绑定(bind)前缀是什么意思?

转载 作者:行者123 更新时间:2023-12-03 14:39:16 25 4
gpt4 key购买 nike

我在我的 android 应用程序中为自定义小部件制作了一个 xml 文件,错误是:

Error parsing XML: unbound prefix



这是我的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"

此后,您为自定义 View 定义的任何自定义属性元素将被称为:
mynamespace:my_defined_attribute="success"

代替 :
android:layout_width="fill_parent"

关于android-layout - 解析 XML 时,未绑定(bind)前缀是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6329295/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com