自定义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对象。
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/203941.html原文链接:https://javaforall.net
