【AndroidStudio问题记录】Error: Found item xxx more than one time解决方法

文章讲述了在Android应用开发中遇到的一个错误,即在res/values/atts.xml文件中,属性isHardwareAccel被两个不同的View风格重复定义。解决方案是将属性定义抽取到顶层,然后在各个View中引用,以消除重复并修复编译错误。
摘要由CSDN通过智能技术生成

【问题】

res/values/atts.xml文件中定义了isHardwareAccel属性。运行产生了Error: Found item Attr/tabTextSize more than one time,这句话的意思是错误:发现项目attr/isHardwareAccel定义不止一次。

    public HdrPictureSurfaceView(Context context, AttributeSet attrs) {
        super(context, attrs);
        try (TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.HdrPictureSurfaceView)) {
            mIsHardwareAccel = attributes.getBoolean(R.styleable.HdrPictureSurfaceView_isHardwareAccel, false);
        }

        init();
    }
<resources>
    <declare-styleable name="ImageSurfaceView">
        <attr name="isHardwareAccel" format="boolean"/>
    </declare-styleable>
    <declare-styleable name="HdrPictureSurfaceView">
        <attr name="isHardwareAccel" format="boolean"/>
    </declare-styleable>
</resources>

【原因】

重复定义isHardwareAccel属性,将<attr name="isHardwareAccel" format="boolean"/>抽来,然后在每个View里面调用就可以了。更改如下:

<resources>
    <attr name="isHardwareAccel" format="boolean"/>
    <declare-styleable name="ImageSurfaceView">
        <attr name="isHardwareAccel"/>
    </declare-styleable>
    <declare-styleable name="HdrPictureSurfaceView">
        <attr name="isHardwareAccel"/>
    </declare-styleable>
</resources>

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值