Android_自定义View
2016-03-21 10:30
513 查看
@作者 : 西野奈留
@博客:http://blog.csdn.net/narunishino
-2016/4/08-更新-
-2016/3/28-更新-
-2016/3/21-
步骤:(java代码)
1. 继承view。
2. 添加构造方法。在构造方法中初始化属性和画笔。//参考[android开发进阶(何红辉)P36]
3. 系统从属性中获取widthMeasureSpec和heightMeasureSpec两个值,我们在重写onMeaure方法中,根据这两个值的specMode来自定义大小。//参考[android群英传(徐宜生)P36]。
4. 重写onDraw方法,在onDraw方法里面绘制文字图形图片。
1. 在valus–>attrs.xml文件(自己新建)中写上你要自定义的属性。
2. 在xml里面写上你要显示的view(不用管位置什么的,代码如下)。
3. 在java文件中重写
——1. onMeasure方法 ,//获取从xml中传过来的信息然后在这里,手动测量子view大小并得到结果从而确定了子view本身的大小。
——2. onLayout方法 ,//获取从xml中传过来的信息然后在这里,确定各个子view放在哪个位置(所以上面说不用管位置什么的 )。
——3. onDraw方法,//获取从xml中传过来的信息然后在这里,画图。
onFinishInflate //调用1次
onMeasure //调用不定次
onSizeChanged //调用1次
onLayout //调用不定次
onDraw //调用不定次
参考:
http://www.imooc.com/learn/300
http://blog.csdn.net/dmk877/article/details/49558367
-End-
@博客: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
//假设你自定义的是viewGroup1. 在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-
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories