09自定义组合控件总结
来源:互联网 发布:网络诈骗案立案 编辑:程序博客网 时间:2024/05/17 20:43
第一步:
自定义一个View,一般来说,继承了相对布局或者线性布局。(必须为ViewGroup的子类)
第二步:
实现父类的构造方法,一般来说,需要在构造方法里初始化自定义的布局文件
第三步:
根据一些需要,定义一些API方法。
//============================================
第四步:
根据需要,自定义控件的属性,可以参照TextView的属性;
第五步:
自定义命名空间,例如:
xmlns:owndefine="http://schemas.android.com/apk/res/com.ustc.mobilemanager"
后面的是应用的包名。
第六步:
自定义属性,在res/values目录下的attrs.xml文件
如:
<?xml version="1.0" encoding="utf-8"?><resources> <declare-styleable name="TextView"> <attr name="title" format="string" /> <attr name="desc_on" format="string" /> <attr name="desc_off" format="string" /> </declare-styleable> </resources>
第七步:
使用我们自定义的属性。
如:
<attr name="title" format="string" /> <attr name="desc_on" format="string" /> <attr name="desc_off" format="string" />
第八步:
在自定义控件的带有两个参数的构造方法里,使用AttributeSet取出属性值,取出后关联自定义布局文件对应的控件。
String title = attrs.getAttributeValue("http://schemas.android.com/apk/res/com.ustc.mobilemanager","title");desc_on = attrs.getAttributeValue("http://schemas.android.com/apk/res/com.ustc.mobilemanager","desc_on");desc_off = attrs.getAttributeValue("http://schemas.android.com/apk/res/com.ustc.mobilemanager","desc_off");tv_title.setText(title);
0 0
- 09自定义组合控件总结
- 自定义控件-组合控件
- 自定义组合控件,组合模式
- android 自定义组合控件总结(两个Button点击切换)
- Android自定义组合控件
- android自定义组合控件
- 自定义组合控件
- 1.11 自定义组合控件
- 自定义组合控件
- 自定义组合控件
- 自定义组合控件
- 自定义组合控件.txt
- Android自定义组合控件
- 07自定义组合控件
- 自定义组合控件
- android组合自定义控件
- android 自定义组合控件
- 自定义组合控件
- 两圆相交求面积
- Xcode6中如何添加pch文件
- 月总结--笔记
- 程序分text, data (initialized), bss, stack, heap几个段
- STL解读-rebind的目的就是再定义一个struct (allocator), 这个allocator能分配 _Other类型的元素。
- 09自定义组合控件总结
- JSP调用javabean报错处理方法
- NYOJ 448 寻找最大数
- Jquery主要控件的取值、赋值,包括textbox,button,lable,radio,checkbox,selected
- hdoj.4324 Triangle LOVE【拓扑排序】 20141201
- SQL与NOSQL
- STL 中 sort map list tree 函数用法简介,数据结构的库函数
- 2014腾讯实习一面面试题
- 第十四周项目六 阅读程序(4、5、6)