【问题标题】:Custom XML tags won't settle?自定义 XML 标记无法解决?
【发布时间】: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


【解决方案1】:

@Harism - 谢谢,就是这样。我认为整数是默认设置,不需要指定。现在可以了。如果您将评论更改为答案,我将给予您功劳。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-01
    • 2020-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-19
    • 1970-01-01
    相关资源
    最近更新 更多