android 自定义View
2016-05-17 09:43
274 查看
自定义View分为三个步骤
onMeasure 测量宽高
onLayout 给空间定位
onDraw 绘制控件
自定义View 的几种实现
1.继承View
完成测量需要注意的细节
onMeasure 测量宽高
onLayout 给空间定位
onDraw 绘制控件
自定义View 的几种实现
1.继承View
完成测量需要注意的细节
int mWidth; int mHeight; @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec,heightMeasureSpec); int widthMode = MeasureSpec.getMode(widthMeasureSpec); int heightMode=MeasureSpec.getMode(heightMeasureSpec); int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); //是否是warp_content模式 if (widthMode==MeasureSpec.AT_MOST&&heightMode==MeasureSpec.AT_MOST){ setMeasuredDimension(mWidth,mHeight); }else if(widthMode==MeasureSpec.AT_MOST){ setMeasuredDimension(mWidth,heightSize); }else if (heightMode==MeasureSpec.AT_MOST){ setMeasuredDimension(widthSize,mHeight); } }
相关文章推荐
- Android 上下文菜单(长摁弹出)
- Android开发中常用的工具类
- android 控件注意点
- android:showAsAction = "never"那么这句话是做什么用的呢
- ubuntu16的android studio无法输入中文的折腾流程
- android 使用LocationClient获取精度,纬度坐标
- android 自定义ProgressBar
- Android开发 如何快速实现分享功能
- 文章标题
- Android百度定位API使用方法
- android之图片切圆角
- Android 异步消息处理机制 让你深入理解 Looper、Handler、Message三者关系
- Android Dev Intro - Camera addCallbackBuffer
- android布局属性
- Android 自定义时区
- androidstudio无法启动,Failed to create a child event loop
- Android 自定义优惠券布局
- android应用程序调用支付宝接口
- (android)Can't Create handler inside thread that has not called Looper.prepare()
- Context都没弄明白,还怎么做Android开发?