首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误:在来自http://developer.android.com的自定义视图中找不到属性的资源标识符

错误:在来自http://developer.android.com的自定义视图中找不到属性的资源标识符
EN

Stack Overflow用户
提问于 2013-08-18 19:12:53
回答 3查看 4.6K关注 0票数 2

按照http://developer.android.com中的教程,我正在学习开发安卓应用程序。

现在我在http://developer.android.com/training/custom-views/create-view.html上工作,当我构建应用程序时,我得到了错误:

代码语言:javascript
复制
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'showText' in package 'com.example.android.customviews.charting'
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'labelHeight' in package 'com.example.android.customviews.charting'
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'labelWidth' in package 'com.example.android.customviews.charting'
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'labelY' in package 'com.example.android.customviews.charting'
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'labelPosition' in package 'com.example.android.customviews.charting'
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'highlightStrength' in package 'com.example.android.customviews.charting'
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'pieRotation' in package 'com.example.android.customviews.charting'
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'labelColor' in package 'com.example.android.customviews.charting'
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'autoCenterPointerInSlice' in package 'com.example.android.customviews.charting'
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'pointerRadius' in package 'com.example.android.customviews.charting'

我从网站上下载了代码,并按原样安装,没有做任何更改,所以main.xml是

代码语言:javascript
复制
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res/com.example.android.customviews"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
<com.example.android.customviews.charting.PieChart
        android:id="@+id/Pie"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:layout_weight="100"
        custom:showText="true"
        custom:labelHeight="20dp"
        custom:labelWidth="110dp"
        custom:labelY="85dp"
        custom:labelPosition="left"
        custom:highlightStrength="1.12"
        android:background="@android:color/white"
        custom:pieRotation="0"
        custom:labelColor="@android:color/black"
        custom:autoCenterPointerInSlice="true"
        custom:pointerRadius="4dp"
        />
<Button
        android:id="@+id/Reset"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/reset_button"
        />
</LinearLayout>

和名称空间是相同的。

你能帮助我理解为什么我会得到这些错误吗?非常感谢。

EN

回答 3

Stack Overflow用户

发布于 2014-03-20 07:26:09

我也遇到了同样的问题,答案就在这个link中。

简而言之,您需要替换

代码语言:javascript
复制
http://schemas.android.com/apk/res/com.example.android.customviews

使用

代码语言:javascript
复制
http://schemas.android.com/apk/lib/com.example.android.customviews

即从/res//lib/

票数 18
EN

Stack Overflow用户

发布于 2015-07-16 11:36:31

我从Android.com下载了同样的自定义演示,也遇到了同样的问题。

改变

代码语言:javascript
复制
xmlns:custom="http://schemas.android.com/apk/res/com.example.android.customviews"

到任何一个

代码语言:javascript
复制
xmlns:custom="http://schemas.android.com/apk/lib/com.example.android.customviews"

代码语言:javascript
复制
xmlns:custom="http://schemas.android.com/apk/res-auto"

起作用了。它们之间有一些不同,我发现第二个解决方案完美地满足了我的需求。我不知道它为什么有用。

票数 1
EN

Stack Overflow用户

发布于 2013-09-11 16:18:01

我遇到了同样的问题,我认为你的自定义属性不属于正确的namespace.You可以得到customview_panda的演示,看看main.xml中的自定义属性,你就会明白了。https://github.com/pandabo1985/Android_App_Prac

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18298460

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档