如何避免CustomView中资源'attr / *'的重复值

问题描述 投票:1回答:1

如果我导入:

CustomViewA

<declare-styleable name="CustomViewA">
        <attr name="min" format="float"/>
        <attr name="max" format="float"/>
</declare-styleable>

CustomViewB

<declare-styleable name="CustomViewB">
        <attr name="min" format="float"/>
        <attr name="max" format="float"/>
</declare-styleable>

这将失败,说明minmax是重复的。我以为Android会以declare-styleable name来区分,但我猜不会。如此说来,命名自定义视图attr的最佳方法是什么,以避免将来出现任何可能的重复值冲突?

到目前为止,我唯一的解决方案是:

<attr name="minForMyCustomViewHopingNoOneUsesThisName" format="float"/>

糟透了。

android android-custom-view android-styles android-attributes
1个回答
0
投票

使其独特是最终的答案。我准备使用

<attr name="custom_view_a_min" format="float"/>
<attr name="custom_view_b_min" format="float"/>
© www.soinside.com 2019 - 2024. All rights reserved.