使用自定义属性报错 No resource identifier found for attribute 'widthFactor' in package

今天在按以前一样使用自定义属性, 在attrs.xml中添加 

<declare-styleable name="FitSizeImageView">
        <attr name="widthFactor" format="integer" />
        <attr name="heightFactor" format="integer" />
</declare-styleable>
然后在要使用这个属性的布局文件中加入了资源文件命名空间申明:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    <span style="color:#ff0000;">xmlns:lock="http://schemas.android.com/apk/com.yzh.lock"</span>
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/bg_color"
    android:orientation="vertical" >


但是在设置资源属性后一直会报错:

No resource identifier found for attribute 'widthFactor' in package, 找了半天还以为是包名写错了, 最后发现android有个限制,

当属性资源被定义在一个Library中的时候, 命名空间固定为: http://schemas.android.com/apk/res-auto, 

于是将命名空间申明改成:

xmlns:lock="http://schemas.android.com/apk/<span style="color:#ff0000;">res-auto</span>"
结果报错就消失了.




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值