我正在编写一些自定义视图,它们共享一些相同的命名属性.在attrs.xml
中各自的<declare-styleable>
部分中,我想对属性使用相同的名称:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyView1">
<attr name="myattr1" format="string" />
<attr name="myattr2" format="dimension" />
...
</declare-styleable>
<declare-styleable name="MyView2">
<attr name="myattr1" format="string" />
<attr name="myattr2" format="dimension" />
...
</declare-styleable>
</resources>
我得到一个错误,说myattr1
和myattr2
已经被定义了.我发现应该在MyView2
中省略myattr1
和myattr2
的format
属性,但如果这样做,我会在控制台中得到以下错误:
[2010-12-13 23:53:11 - MyProject] ERROR: In <declare-styleable> MyView2, unable to find attribute
有没有办法做到这一点,也许是某种名称空间(只是猜测)?