今天在按以前一样使用自定义属性, 在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>"
结果报错就消失了.