<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" > <!-- --> <FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" > <com.example.test.MeasTestLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
</com.example.test.MeasTestLayout>
</FrameLayout> <FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" > <com.example.test.MeasTestLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</com.example.test.MeasTestLayout>
</FrameLayout> <FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" > <com.example.test.MeasTestLayout
android:layout_width="match_parent"
android:layout_height="100dp" >
</com.example.test.MeasTestLayout>
</FrameLayout> <FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" > <com.example.test.MeasTestLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
</com.example.test.MeasTestLayout>
</FrameLayout> <FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" > <com.example.test.MeasTestLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</com.example.test.MeasTestLayout>
</FrameLayout> <FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" > <com.example.test.MeasTestLayout
android:layout_width="match_parent"
android:layout_height="100dp" >
</com.example.test.MeasTestLayout>
</FrameLayout> <FrameLayout
android:layout_width="match_parent"
android:layout_height="100dp" > <com.example.test.MeasTestLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
</com.example.test.MeasTestLayout>
</FrameLayout> <FrameLayout
android:layout_width="match_parent"
android:layout_height="100dp" > <com.example.test.MeasTestLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</com.example.test.MeasTestLayout>
</FrameLayout> <FrameLayout
android:layout_width="match_parent"
android:layout_height="100dp" > <com.example.test.MeasTestLayout
android:layout_width="match_parent"
android:layout_height="50dp" >
</com.example.test.MeasTestLayout>
</FrameLayout> </FrameLayout>
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO Auto-generated method stub
super.onMeasure(widthMeasureSpec, heightMeasureSpec); print(widthMeasureSpec, heightMeasureSpec);
} private void print(int widthMeasureSpec, int heightMeasureSpec){
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
log("begin>>>");
log("width -- mode: "+getMode(widthMode) +" size: "+MeasureSpec.getSize(widthMeasureSpec));
log("height -- mode: "+getMode(heightMode) +" size: "+MeasureSpec.getSize(heightMeasureSpec));
log("<<<");
}
- ::27.155: D/View(): measure: begin>>>
- ::27.155: D/View(): measure: width -- mode: EXACTLY size:
- ::27.155: D/View(): measure: height -- mode: AT_MOST size: 1599->1467
- ::27.155: D/View(): measure: <<<
- ::27.155: D/View(): measure: begin>>>
- ::27.155: D/View(): measure: width -- mode: EXACTLY size:
- ::27.155: D/View(): measure: height -- mode: AT_MOST size: 1599->1467
- ::27.155: D/View(): measure: <<<
- ::27.155: D/View(): measure: begin>>>
- ::27.155: D/View(): measure: width -- mode: EXACTLY size:
- ::27.155: D/View(): measure: height -- mode: EXACTLY size:
- ::27.155: D/View(): measure: <<<
- ::27.155: D/View(): measure: begin>>>
- ::27.155: D/View(): measure: width -- mode: EXACTLY size:
- ::27.155: D/View(): measure: height -- mode: EXACTLY size: 1599->1467
- ::27.155: D/View(): measure: <<<
- ::27.155: D/View(): measure: begin>>>
- ::27.155: D/View(): measure: width -- mode: EXACTLY size:
- ::27.155: D/View(): measure: height -- mode: AT_MOST size: 1599->1467
- ::27.155: D/View(): measure: <<<
- ::27.155: D/View(): measure: begin>>>
- ::27.155: D/View(): measure: width -- mode: EXACTLY size:
- ::27.155: D/View(): measure: height -- mode: EXACTLY size:
- ::27.155: D/View(): measure: <<<
- ::27.155: D/View(): measure: begin>>>
- ::27.155: D/View(): measure: width -- mode: EXACTLY size:
- ::27.155: D/View(): measure: height -- mode: EXACTLY size:
- ::27.155: D/View(): measure: <<<
- ::27.155: D/View(): measure: begin>>>
- ::27.155: D/View(): measure: width -- mode: EXACTLY size:
- ::27.155: D/View(): measure: height -- mode: AT_MOST size:
- ::27.155: D/View(): measure: <<<
- ::27.155: D/View(): measure: begin>>>
- ::27.155: D/View(): measure: width -- mode: EXACTLY size:
- ::27.155: D/View(): measure: height -- mode: EXACTLY size:
- ::27.155: D/View(): measure: <<<
结论:、自定义控件中的onMeasure方法接收的参数的Mode与它的父控件的w、h以及它自身的宽高有关
2、如果自定义控件自身的高度为固定的dp值,传入的参数的mode一定是EXACTLY
3、如果自定义控件自身的高度为wrap_content,传入的参数的mode一定是AT_MOST
4、如果自定义控件自身的高度为match_parent,其父控件的高度为固定dp值,传入的参数的mode一定是EXACTLY
5、如果自定义控件自身的高度为match_parent,其父控件的高度为wrap_content,传入的参数的mode一定是AT_MOST
6、如果自定义控件自身的高度为match_parent,其父控件的高度为match_parent,传入的参数的mode依赖更上层的父控件,并且可能在多次onMeasure中变化
7、MeasureSpec.UNSPECIFIED是未指定尺寸,这种情况不多,一般都是父控件是AdapterView,通过measure方法传入的模式。

MeasureSpec 的三中类型的更多相关文章

  1. MongoDB 搭建分片集群

    在MongoDB(版本 3.2.9)中,分片是指将collection分散存储到不同的Server中,每个Server只存储collection的一部分,服务分片的所有服务器组成分片集群.分片集群(S ...

  2. OpenMP并行构造的schedule子句详解 (转载)

    原文:http://blog.csdn.net/gengshenghong/article/details/7000979 schedule的语法为: schedule(kind, [chunk_si ...

  3. PHP API 框架开发的学习

    基于互联网的应用正变得越来越普及,在这个过程中,有更多的站点将自身的资源开放给开发者来调用.对外提供的API 调用使得站点之间的内容关联性更强,同时这些开放的平台也为用户.开发者和中小网站带来了更大的 ...

  4. GFS Google File System(中文翻译)

    Google文件系统 GFS是一个可扩展的分布式文件系统,用于大型的.分布式的.对大量数据进行访问的应用.它运行于廉价的普通硬件上,但可以提供容错功能.它可以给大量的用户提供总体性能较高的服务. 1. ...

  5. 如何利用SVN合并代码

    一.  背景     平时在进行开发时,一般都会有多版本同时进行,包括项目版本.周版本.紧急版本等,当某一个版本具备上线条件后,需要在上一个已发布的版本基础上进行发布,才能够避免出现版本相互覆盖,因此 ...

  6. JSON 理解

    转自: http://blog.csdn.net/qyf_5445/article/details/8635578 (json很全面的理解) http://www.cnblogs.com/haitao ...

  7. DeepLearning.ai学习笔记(四)卷积神经网络 -- week1 卷积神经网络基础知识介绍

    一.计算机视觉 如图示,之前课程中介绍的都是64* 64 3的图像,而一旦图像质量增加,例如变成1000 1000 * 3的时候那么此时的神经网络的计算量会巨大,显然这不现实.所以需要引入其他的方法来 ...

  8. Android View的绘制过程

    首先是view的绘制过程~最主要的分三部分 measure layout draw 看字面意思,计算,布局,画~ android中控件相当于是画在一个无限大的画布上的,那就产生了几个问题 画布无限大, ...

  9. 【安卓网络请求开源框架Volley源码解析系列】初识Volley及其基本用法

    在安卓中当涉及到网络请求时,我们通常使用的是HttpUrlConnection与HttpClient这两个类,网络请求一般是比较耗时,因此我们通常会在一个线程中来使用,但是在线程中使用这两个类时就要考 ...

随机推荐

  1. wxpython安装,demo下载

    wxPython介绍      wxPython是Python语言的一套优秀的GUI图形库.wxPython可以很方便的创建完整的.功能键全的GUI用户界面. wxPython安装 本安装采用pip自 ...

  2. Python 导入requests报错No module named requests

    刚开始是在Pycharm里面,发现就是不对,导入老提示No module named requests这个错误.后面发现是指向的python.exe路径不对,到setting里面设置换一下路径就好.

  3. hdu 3466 Proud Merchants 【限制性01背包】+【贪心】

    题目链接:https://vjudge.net/contest/103424#problem/J 转载于:https://www.bbsmax.com/A/RnJW16GRdq/ 题目大意: 有n个商 ...

  4. js滚动分页原理

    <!doctype html><html> <head> <!--声明当前页面的编码集:charset=gbk,gb2312(中文编码),utf-8国际编码- ...

  5. redis 在 php 中的应用(事务 [ Transaction ] 篇)

    本文为我阅读了 redis参考手册 之后编写,注意 php_redis 和 redis-cli 的区别(主要是返回值类型和参数用法) 目录: Transaction(事务) WATCH UNWATCH ...

  6. Ping监控脚本

    需求 内网服务器之间高频率检验延时信息, 脚本特点 多进程,可同时异步监控多个地址,不会互相影响. 使用方式 创建文件夹(可以替换为你自己的,我这里就用我们生产环境的标准目录了) mkdir /dat ...

  7. C# 不同类型对象同名属性赋值

    /// <summary> /// 不同类型对象同名属性赋值 /// </summary> /// <typeparam name="S">源类 ...

  8. c# sqlite 数据库加密

    c# sqlite 数据库加密 2010-05-29 10:55 用了ADO.NET 2.0 SQLite Data Provider这样可以直接利用它来创建一个加密的sqlite数据库.有关c#代码 ...

  9. AngularJS中使用$http对MongoLab数据表进行增删改查

    本篇体验使用AngularJS中的$http对MongoLab数据表进行增删改查. 主页面: <button ng-click="loadCourse()">Load ...

  10. vue2.0实现倒计时的插件(时间戳 刷新 跳转 都不影响)

    我发现好多倒计时的插件,刷新都会变成从头再来,于是自己用vue2.0写了一个,测试通过,直接上代码 如下是组件代码: <template> <span :endTime=" ...