1.建立一个类,继承RelativeLayout
2.写好布局
3.在res/values/attr.xml 中自定义其属性
5.在class中实例化自定义属性、布局控件
在eclipse中需要将声明自定义view 跟属性的格式分开
studio中是可以一起写的
<resources>
<span style="white-space:pre"> </span><!--name 对应的定义属性,format 就是属性值的格式 -->
<attr name="title_text" format="string" />
<attr name="title_leftimg" format="reference" />
<attr name="title_size" format="dimension" />
<attr name="title_color" format="color" />
<span style="white-space:pre"> </span><!--声明这个 自定义view,name一般用class名,下面的attr标签就是定义的属性 -->
<declare-styleable name="CustomTitleView">
<attr name="title_text" />
<attr name="title_leftimg" />
<attr name="title_size" />
<attr name="title_color" />
</declare-styleable>
</resources>
下面是从网上copy别人的一些format格式对应的意思
reference 表示引用,参考某一资源ID