我正在写一些自定义视图,它们共享一些同名的属性.在他们各自的<declare-styleable>部分,attrs.xml我想对属性使用相同的名称:
<?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>
Run Code Online (Sandbox Code Playgroud)
我收到一个错误,说明myattr1并且myattr2已经定义了.我发现我应该省略formatfor myattr1和myattr2in 的属性MyView2,但如果我这样做,我在控制台中获得以下错误:
[2010-12-13 23:53:11 - MyProject] ERROR: In <declare-styleable> MyView2, unable to find attribute
Run Code Online (Sandbox Code Playgroud)
有没有办法可以实现这一点,也许某种命名空间(只是猜测)?
android android-custom-view android-view android-custom-attributes