Android View 四个构造函数

来源:互联网 发布:手机端html模板源码 编辑:程序博客网 时间:2024/05/29 04:56

自定义View的时候,自然要和它的构造函数打交道,目前 一共有四个构造函数,大多数情况下,使用第二个就够了,第一个没什么大用,第三个和第四个都是跟style和theme有关的。

在View类中有四个构造函数,涉及到多个参数,
Context:上下文
AttributeSet attrs: 从xml中定义的参数
int defStyleAttr :主题中优先级最高的属性
int defStyleRes : 优先级次之的内置于View的style
他们的优先级是:
Xml直接定义 > xml中style引用 > defStyleAttr > defStyleRes > theme直接定义

摘抄自:Android View 四个构造函数详解