一、实现方式

1.继承View重写onDraw方法

2.继承View、ViewGroup 派生特殊的View、Layout 例如:继承TextView  继承LinearLayout等等


二、注意事项

1.让View支持wrap_content

2.让View支持padding

3.尽量不要在View中使用Handler


三、其它

1、自定义View如何提供获取View属性的接口

第一步:在res/values/attr.xml 定义一个declare-styleable

第二步:在自定view代码中使用

第三步:在布局xml添加xmlns:PreferenceLayout(view名称)=“http://schemas.android.com/apk/res/View所在包名”


参考:https://www.jianshu.com/p/9862cddca1b3