<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. 安装及配置sublime

    纯个人笔记,粗略编写,有时间再修改 参考:关于Sublime text3 配置及插件整理 参考:https://github.com/boontime/sublime-text3-config 参考: ...

  2. 域名解析到Nginx服务器项目上

    第一步:先将域名解析到 IP 上 解析完后,如下 第二步:Nginx服务器配置servername 修改 /usr/local/nginx/conf/nginx.conf (你的配置文件可能不在这个目 ...

  3. Web轻量级扫描工具Skipfish

    Web轻量级扫描工具Skipfish 1. Skipfish 简介 2. Skipfish 基本操作 3.身份认证 一. Skipfish 简介 Skipfish是一款主动的Web应用程序安全侦察工具 ...

  4. Python常用模块--base64

    作用:对一些保密性不强的信息进行加密,变为人类不能直接理解的字符串,但是可以反向解密,是一种‘防君子,不防小人’的措施. 例如:在一些项目中,接口的报文是通过base64加密传输的,所以在进行接口自动 ...

  5. 基于C++11实现线程池的工作原理

    目录 基于C++11实现线程池的工作原理. 简介 线程池的组成 1.线程池管理器 2.工作线程 3.任务接口, 4.任务队列 线程池工作的四种情况. 1.主程序当前没有任务要执行,线程池中的任务队列为 ...

  6. AGC027 E - ABBreviate

    目录 题目链接 题解 代码 题目链接 AGC027 E - ABBreviate 题解 神仙啊 建议查看https://img.atcoder.jp/agc027/editorial.pdf 定义a ...

  7. [POI2011]Rotacje na drzewie (2)/[BZOJ3702]二叉树

    [POI2011]Rotacje na drzewie (2) 题目大意: 一棵有\(n\)个叶子结点的二叉树,每个叶子结点有一个权值,恰好是\(1\sim n\)的一个排列,你可以任意交换每一对子结 ...

  8. 创建django出现的问题

    1.创建表报错 2.静态文件和模板配置 3.在表格插入数据库信息 4.继承模板 5.找不到post请求数据

  9. 如何将Object类型转换成String类型

    1. Object.toString() obj.toString() 注意:必须保证Object不是null值,否则将抛出NullPointerException异常. 2. (String)Obj ...

  10. solr中的一些常见错误

    (1)Caused by: java.lang.ClassNotFoundException: Unable to load jdbcDataSource or org.apache.solr.han ...