Android_自定义View
来源:互联网 发布:linux退出命令行界面 编辑:程序博客网 时间:2024/05/22 17:30
@作者 : 西野奈留
@博客:http://blog.csdn.net/narunishino
-2016/4/08-更新-
-2016/3/28-更新-
-2016/3/21-
view
//假设自定义的是view
步骤:(java代码)
1. 继承view。
2. 添加构造方法。在构造方法中初始化属性和画笔。//参考[android开发进阶(何红辉)P36]
3. 系统从属性中获取widthMeasureSpec和heightMeasureSpec两个值,我们在重写onMeaure方法中,根据这两个值的specMode来自定义大小。//参考[android群英传(徐宜生)P36]。
4. 重写onDraw方法,在onDraw方法里面绘制文字图形图片。
viewGroup
//假设你自定义的是viewGroup
1. 在valus–>attrs.xml文件(自己新建)中写上你要自定义的属性。
2. 在xml里面写上你要显示的view(不用管位置什么的,代码如下)。
3. 在java文件中重写
——1. onMeasure方法 ,//获取从xml中传过来的信息然后在这里,手动测量子view大小并得到结果从而确定了子view本身的大小。
——2. onLayout方法 ,//获取从xml中传过来的信息然后在这里,确定各个子view放在哪个位置(所以上面说不用管位置什么的 )。
——3. onDraw方法,//获取从xml中传过来的信息然后在这里,画图。
<?xml version="1.0" encoding="utf-8"?><com.atozmak.circleandroundimageviewdemo.widgets.ArcMenu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:atoz="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" atoz:position="right_bottom" atoz:radius="150dp"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/composer_music" android:tag="Music" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/composer_place" android:tag="Place" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/composer_sleep" android:tag="Sleep" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/composer_thought" android:tag="Sun" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/composer_with" android:tag="People" /></com.atozmak.circleandroundimageviewdemo.widgets.ArcMenu>
执行顺序
- CustomView构造函数 //调用1次
- onFinishInflate //调用1次
- onMeasure //调用不定次
- onSizeChanged //调用1次
- onLayout //调用不定次
- onDraw //调用不定次
参考:
http://www.imooc.com/learn/300
http://blog.csdn.net/dmk877/article/details/49558367
-End-
- Android_自定义View
- android_自定义折叠View
- Android_自定义View拖拽重绘
- Android_自定义删除View
- Android_自定义倒计时View
- Android_自定义签到View
- Android_自定义波纹view
- Android_自定义View、Fragment
- Android_自定义View测量模式
- Android_自定义view动画按钮
- Android_自定义View之跳动的loading
- Android_自定义view设置控件位置
- Android_自定义描述进度的View
- Android_自定义View-和view的监听事件
- Android_自定义View的三种实现方式
- Android_自定义View---三种事件的触发、自定义View属性
- Android_指引点View
- Android_自定义控件
- Java中数组的问题(三)
- 二维码识别IOS或Android客户端
- iBatis框架使用 编程4步
- VR虚拟现实小白入门:18个VR专业术语解析!
- JSP/Servlet工作原理
- Android_自定义View
- 319. Bulb Switcher
- Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解实例详解
- Qt文档中文版
- Wpf下使用lib的注意事项
- Object.create() 是什么?继承(继承特定的)
- Java——DOM方式生成XML
- 第七届蓝桥杯C/C++ A组 省赛
- 大对象类型数据存储