天天看点

自定义view在xml中的名称

String s = 包名 + "." + 类名

其中包名不用更改顺序,左侧怎么写就怎么写

包是testhelloworld.test.hui,类是TouchView

<testhelloworld.test.hui.TouchView
      android:layout_width="match_parent"
      android:layout_height="match_parent"/>
           

包名出错会导致error inflating class ,另外类要继承参数为(Context context, AttributeSet attrs)的构造函数否则会导致一样的报错。

另外包的命名习惯和网址相反,如上例hui.test.testhelloworld为正确命名方式。