<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. In Action HDU3339

    这是最短路问题和01背包问题的相结合 第一次用01背包 把j打成了i检查了半个小时  下次要注意! 使用的油耗相当于容量  而power相当于价值 先用dijkstra把从基地到所有路的最短情况算出来 ...

  2. C语言 —— 贪吃蛇

    参考视频:https://www.bilibili.com/video/av29580072/?p=1 GreedySnake.h #ifndef GREEDYSNAKE_H_INCLUDED #de ...

  3. request中获取post的json对象数据content-type=“text/plain”

    其实采用http://www.cnblogs.com/SimonHu1993/p/7295750.html中的方法一都能获取到,就是通过获取request中的流数据,拿到json数据,理论上应该适用各 ...

  4. 从零搭建ES搜索服务(一)基本概念及环境搭建

    一.前言 本系列文章最终目标是为了快速搭建一个简易可用的搜索服务.方案并不一定是最优,但实现难度较低. 二.背景 近期公司在重构老系统,需求是要求知识库支持全文检索. 我们知道普通的数据库 like ...

  5. 论maven release的必要性

    大多数java开发的小伙伴都用过maven来对包进行管理.在自己写项目的过程中,对自己的项目也会进行groupdId,artifactId,version的配置.下面我们来对着3个配置进行简单说明. ...

  6. 一些数学上的概念理解(持续更新qwq)

    致敬百度百科qwq 本文摘自百度百科,只是对于信竞范围内的知识做一个小总结qwq,持续更新ing··· 满射: 如果每个可能的像至少有一个变量映射其上(即像集合B中的每个元素在A中都有一个或一个以上的 ...

  7. python的条件与循环1

    一.if语句 功能 计算机又被称作电脑,意指计算机可以像人脑一样,根据周围环境条件(即expession)的变化做出不同的反应(即执行代码) if语句就是来控制计算机实现这一功能. if语句小结 if ...

  8. AppleScript脚本学习记录《二》

    关于AppleScript 说到AppleScript,可能涉及到三个含义: 1.AppleScript语言:就是苹果脚本的语言,用来编写运行于Mac系统的脚本. 2.AppleScript脚本:就是 ...

  9. [__NSArrayM insertObject:atIndex:]: object cannot be nil'

    错误描述:如下图 分析原因: 1.插入的对象为空了 2.[__NSSetM addObject:] object cannot be nil [__NSArrayM insertObject:atIn ...

  10. ES6语法篇(其一)

    转载链接:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/es6-grammar-part-one/ 一.let命令 基本用法:ES ...