自定义View,将他用于布局文件中,在XML作为布局元素来布局的话,必须使用完整路径名,也就是包名加类名来引用,用com.example.lklknbnhh.myview.MyView来进行引用。
自定义一个View,必须派生实现基类View的三个构造函数
View(Context context) //Simple constructor to use when creating a view from code
View(Context context, AttributeSet attrs) //Constructor that is called when inflating a view from XML
View(Context context, AttributeSet attrs, int defStyle) //Perform inflation from XML and apply a class-specific base style
第二个和第三个构造函数对于XML这种引用方式是必须实现的,这三个构造函数应该是在不同的应用场合来实例化一个View对象。

本文详细介绍了Android中自定义View的实现方法,包括如何在XML布局文件中引用自定义View及其实现所需的三个构造函数。
2778

被折叠的 条评论
为什么被折叠?



