自定义控件

来源:互联网 发布:淘宝网商城女装新款 编辑:程序博客网 时间:2024/06/06 18:49

1、自定义View的属性

2、在View的构造方法中获得我们自定义的属性

3、重写onDraw

 <attr name="titleText" format="string" />    <attr name="titleColor" format="color" />    <attr name="titleTextSize" format="dimension" />    <declare-styleable name="CustomTitleView">        <attr name="titleText" />        <attr name="titleColor" />        <attr name="titleTextSize" />    </declare-styleable>

format是值该属性的取值类型:

一共有:string,color,demension,integer,enum,reference,float,boolean,fraction,flag

在构造方法中进行获取属性的值,进行测量  ,然后进行绘制

1 0
原创粉丝点击