`

自定义组件

 
阅读更多

自定义控件
 1.抽取layout如:list_item_home.xml
 2.写一个类继承1中的layout,实现父类(相对布局)的构造方法
 3.使用:<my.UI.MycheckUI />
自定义控件的属性:
 1.布局文件里自定义一个命名空间 xmlns:my="http://schemas.android.com/apk/res/my.MySafe"
 2.在res的values目录下描述自定义属性的文件
    <declare-styleable name="SettingItemView">
          <attr name="desc_on" format="string" />
          <attr name="desc_off" format="string" />
          <attr name="title" format="string" />
      </declare-styleable>
 3.在布局文件里写你要用的哪些属性如:my:title
 4.在只有两个参数的构造方法里 其中一个参数attrs封装了所有属性的信息。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics