偶然接触attrs.xml文件,attrs.xml理解为自定义属性,
一般自定义控件时会使用到.
declare-styleable
目的主要是更加灵活的使用自定义控件
例如,你在设计一个控件时,它会有多种形状,不同形状会进行不同方式的处理
attrs.xml是自己创建在values下
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.MaImageView);
//相当于声明一下关联
type = a.getInt(R.styleable.
MaImageView_type, TYPE_CIRCLE);// 默认为Circle
a.recycle();
attrs.xml内
<declare-styleable name="MaImageView">
<attr name="type" format="integer">
<enum name="circle" value="0" />
<enum name="round" value="1" />
</attr>
</declare-styleable>
最后你在使用这个自定义控件时
<test.mylibrary.view.MaImageView android:layout_width="300dp" android:layout_height="300dp"android:scaleType="centerCrop" android:src="@drawable/qqqq"ma:type="round" />