Building Custom Components/建立自定义组件
来源:互联网 发布:淘宝上的人参能吃吗 编辑:程序博客网 时间:2024/04/30 12:04
Building Custom Components/建立自定义组件
文章分类:移动开发
一、android除了内建的众多组件(widget/layout)外,还提供基于View和ViewGroup的成熟组件扩展模型,让你构建自已的组件。
二、常用的内建widget有:Button、TextView、EditText、ListView、CheckBox、RadioButton、Gallery、Spinner、AutoCompleteTextView、ImageSwitcher、TextSwitcher。常用的内建layout有:LinearLayout、FrameLayout、RelativeLayout。
三、需要新建自定义widget的情况有以下几种:完全自定义的功能及外观,像时钟、音量控制等;把多个内建widget组合在一起形成新的一个大组件;
四、简单的新建组件方法:新建一个类,继承自view或它的子类。重写父类的部份方法。
五、完全自定义组件的方法:继承view;重写onMeasure和onDraw方法。默认下onDraw不做任何事情,onMeasure设置控件大小为100*100。最后重写一些on方法及添加相关属性。
六、重写onDraw。onDraw方法会传入一个canvas对像。你可以用它来来设置控件的包观方面的事情,包括2d graphics。(如果要用3d graphics,请用SurfaceView代替View)。
七、重写onMeasure。在onMeasure方法中调用setMeasuredDimension(int width,int height)方法 ,告诉容器当前控件的大小。
八、创建组合型自定义组件。继承layout,然后用xml或编程方式放置各种组件;从构造方法中得到相关参数,并传递给各组件;按需要,重写一些事件方法(onXXX);在创建组合型自定义组件时重写onDraw与onMeasure不是必需的。
九、在xml中调用自定义组件。组件为内部类:根据类型,标签写View/ViewGroup。然后在class属性中填写具体的类,例如 <View class="com.humanmonth.CusComp$MyComp。组件为一般类:标签直接写全类名。
- Building Custom Components/建立自定义组件
- Building Custom Components/建立自定义组件
- 创建自定义组件Building Custom Components
- Custom Components(自定义组件)
- Building Custom Components
- Custom Components「自定义组件」翻译
- Building Custom JSF UI Components
- Building Custom JSF UI Components
- Android API——自定义组件(Custom Components)
- Building custom JSF UI components(转)
- Custom Components
- Custom Components
- Custom Components
- vue自定义公共组件components
- 创建自定义模板 Building Custom Templates
- Android 用户界面---定制组件(Custom Components)(一)
- Android 用户界面---定制组件(Custom Components)(二)
- Build custom components
- webview ConnectionManager
- 从win7到虚拟机中linux的端口映射
- Android Layout 之 RelativeLayout
- 深入理解C++的动态绑定和静态绑定
- 超分辨率在影像技术中
- Building Custom Components/建立自定义组件
- java与java虚拟机原理
- 特殊的组合问题(解复杂的问题)
- SurfaceView中添加组件
- 设计与思维方式的改变
- Android NDK入门搭建
- the model two
- Android View预估大小
- 获取Expression Blend 4 RC的Key