如果我导入:
自定义 View A (从 Maven 导入)
<declare-styleable name="CustomViewA">
<attr name="min" format="float"/>
<attr name="max" format="float"/>
</declare-styleable>
自定义 View B (从 Maven 导入)
<declare-styleable name="CustomViewB">
<attr name="min" format="float"/>
<attr name="max" format="float"/>
</declare-styleable>
这将失败说 分钟 和 最大 是重复的。我以为 Android 会通过
declare-styleable name
来区分,但猜不到。话虽如此,命名自定义 View 的最佳方法是什么 attr
以避免将来出现任何可能的重复值冲突?到目前为止,我得到的唯一解决方案是:
<attr name="minForMyCustomViewHopingNoOneUsesThisName" format="float"/>
这太糟糕了。
最佳答案
你可以这样做
<attr name="min" format="float" />
<attr name="max" format="float" />
<declare-styleable name="CustomViewA">
<attr name="min" />
<attr name="max" />
</declare-styleable>
<declare-styleable name="CustomViewB">
<attr name="min" />
<attr name="max" />
</declare-styleable>
关于android - 如何避免 CustomView 中资源 'attr/*' 的重复值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60337829/