【发布时间】:2011-05-14 14:37:00
【问题描述】:
我真的很难过。我按照this 链接学习如何为我的视图创建自定义 xml 标记。好吧,据我所知,我做的一切都是正确的。但是eclipse还是折腾error: No resource identifier found for attribute 'radius' in package 'com.theliraeffect.fantasy'
你们可以看看吗?
hexmap.xml
<com.theliraeffect.fantasy.HexMap xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:hexmap="http://schemas.android.com/apk/res/com.theliraeffect.fantasy"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
hexmap:radius="3"/>
attrs.xml
<resources>
<declare-styleable name="HexMap">
<attr name="radius"/>
</declare-styleable>
</resources>
以防万一(虽然我怀疑这与它有什么关系)。
package com.theliraeffect.fantasy;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
public class HexMap extends View {
HexMap(Context context, AttributeSet attrs, int defstyle) {
super(context, attrs, defstyle);
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.hexmap);
a.recycle();
}
}
【问题讨论】:
-
附带说明:除了开始活动(我没有触及)之外,这是整个项目。我开始了一个全新的项目来解决这个问题。
-
从您提供的链接
Non-standard android attributes need to have their type declared,我猜这意味着您必须在 attrs.xml 中为radius添加format=".."。
标签: android xml tags custom-attributes typed-arrays