onMeasure的实现方式
2014-01-18 16:48
218 查看
[code]@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int desiredWidth = 100; int desiredHeight = 100; int widthMode = MeasureSpec.getMode(widthMeasureSpec); int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightMode = MeasureSpec.getMode(heightMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); int width; int height; //Measure Width if (widthMode == MeasureSpec.EXACTLY) { //Must be this size width = widthSize; } else if (widthMode == MeasureSpec.AT_MOST) { //Can't be bigger than... width = Math.min(desiredWidth, widthSize); } else { //Be whatever you want width = desiredWidth; } //Measure Height if (heightMode == MeasureSpec.EXACTLY) { //Must be this size height = heightSize; } else if (heightMode == MeasureSpec.AT_MOST) { //Can't be bigger than... height = Math.min(desiredHeight, heightSize); } else { //Be whatever you want height = desiredHeight; } //MUST CALL THIS setMeasuredDimension(width, height); }
相关文章推荐
- Node.js初探之hello world
- Yii Framework 开发教程(7) 使用CHtml 创建Form
- Yii Framework 开发教程(6) CComponent 组件
- 使用JSTL的sql:query标签制作分页查询遇到NoSuchFieldError: deferredExpression
- Multiply Strings
- Yii Framework 开发教程(5) URL管理
- Yii Framework 开发教程(4) Hangman 猜单词游戏实例
- 使用ACE_Task管理线程
- 套接字编程简介<一>
- Unity3D Resources Load 资源加载测试
- POJ 1062 昂贵的聘礼 (最短路 Dijkstra)
- Yii Framework 开发教程(3) 为应用添加日志
- HDU - 1114 - Piggy-Bank
- Uploadify 结合 Web API 2 上传问题
- centos6.5 安装virtualbox4.3
- 贪心思想题的解题报告
- Mysql的row_format
- 动态规划-钢条切割问题
- Ratgeber - In 3 Tagen Zum Pilzzuchtprofi!
- Yii Framework 开发教程(2) Yii Web应用基础