Android 提供了一组灵活和强大的组件模型来构建自己需要的UI。主要是通过继承 View 和ViewGroup。

Android提供的常用控件,其实也是继承了View 和 ViewGroup,

View的例子:

A partial list of available widgets includes ButtonTextViewEditText,ListViewCheckBoxRadioButtonGallerySpinner, and the more special-purpose AutoCompleteTextViewImageSwitcher, andTextSwitcher.

ViewGroup的例子:

Among the layouts available are LinearLayoutFrameLayoutRelativeLayout, and others. For more examples, see Common Layout Objects.


如果很不幸,这些Android为你预先准备的widgets或layouts不能满足你的需求,那么,就自己动手,丰衣足食。

如果对于现有的widgets或layouts,你只需要修改一小部分就满足需求,那么你只需要继承它,然后重写相应的方法即可;

如果需要大概,那么直接继承View或ViewGroup本身,然后重写一切。


基本方法

1、继承View

2、重写相关方法

3、使用你的View

  1. Extend an existing View class or subclass with your own class. 
  2. Override some of the methods from the superclass. The superclass methods to override start with 'on', for example, onDraw()onMeasure(), and onKeyDown(). This is similar to the on... events in Activity orListActivity that you override for lifecycle and other functionality hooks.
  3. Use your new extension class. Once completed, your new extension class can be used in place of the view upon which it was based.

更多相关文章

  1. Android之获取加载图片宽高问题(getIntrinsicWidth与getwidth的区
  2. Android模拟用户点击的实现方法
  3. 在使用ListFragment的setEmptyText时报java.lang.IllegalStateEx
  4. 查看基于Android(安卓)系统单个进程内存、CPU使用情况的几种方法
  5. WebKit – WebKit For Android
  6. Android(安卓)Http请求方法汇总
  7. android开关飞行模式的方法
  8. 浅谈Java中Collections.sort对List排序的两种方法
  9. Python list sort方法的具体使用

随机推荐

  1. XpmJS —— 小程序后端开发思考和实践
  2. 谈谈使用JS库解决小程序跨页传递消息和数
  3. 支撑百度搜索引擎99.995%可靠名字服务架
  4. 手写spring+springmvc+mybatis框架篇【sp
  5. 新浪微博平台自动化运维演进之路
  6. 大数据平台快速解决方案
  7. 大数据平台架构技术选型与场景运用
  8. 设计模式是什么鬼(原型)
  9. 解决Laravel使用laravel-excel扩展包(maa
  10. 互联网金融风控中的数据科学