首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何避免CustomView中资源'attr/*‘的重复值

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

Stack Overflow用户
提问于 2020-02-21 11:32:27
回答 2查看 790关注 0票数 4

如果我进口:

CustomViewA (从Maven进口)

代码语言:javascript
复制
<declare-styleable name="CustomViewA">
        <attr name="min" format="float"/>
        <attr name="max" format="float"/>
</declare-styleable>

CustomViewB (从Maven进口)

代码语言:javascript
复制
<declare-styleable name="CustomViewB">
        <attr name="min" format="float"/>
        <attr name="max" format="float"/>
</declare-styleable>

如果说minmax是重复的,这将失败。我原以为安卓会与declare-styleable name区别开来,但我猜并非如此。这么说,为自定义视图attr命名的最佳方法是什么,以避免将来发生任何可能的重复值冲突?

到目前为止,我唯一的解决办法是:

代码语言:javascript
复制
<attr name="minForMyCustomViewHopingNoOneUsesThisName" format="float"/>

这太糟糕了。

EN

回答 2

Stack Overflow用户

发布于 2020-02-21 11:44:31

你可以做到的

代码语言:javascript
复制
<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>
票数 4
EN

Stack Overflow用户

发布于 2020-02-21 11:41:09

使它独一无二是最终的答案。我准备用

代码语言:javascript
复制
<attr name="custom_view_a_min" format="float"/>
<attr name="custom_view_b_min" format="float"/>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60337829

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档