<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. mydumper下载安装

    下载地址   https://github.com/maxbube/mydumper [root@gg ~]#cd mydumper [root@gg mydumper]# cmake . -bash ...

  2. 敌兵布阵 HDU1166

    基础线段树 #include<cstdio> #include<iostream> using namespace std; int n,p,a,b,m,x,y,ans; st ...

  3. 021 使用join()将数组转变为字符串

    1.定义用用法 join() 方法用于把数组中的所有元素放入一个字符串. 元素是通过指定的分隔符进行分隔的. 语法 arrayObject.join(separator) 返回值 返回一个字符串.该字 ...

  4. Win 10 启用 Net3.5

    dism.exe /online /enable-feature /featurename:NetFX3 /Source:H:\sources\sxs

  5. canvas学习-----1px线条模糊问题

    canvas有时候会出现1像素的线条模糊不清且好像更宽的情况,如下图: 这样的线条显然不是我们想要的. 这篇文章的目的就是弄清楚里面的原理,以及解决它. 大家都知道屏幕上最小的显示尺寸就是1像素,虽然 ...

  6. C memset

    //#include "stdafx.h" #include <iostream> #include <memory.h> using namespace ...

  7. ftp不能登录报错

    虚拟机装好RedHat后,准备使用filezilla连接,输入IP地址,root用户,密码,快速连接,报错: 530 Permission denied. 故障排除: 1.首先检查系统是否开启了vsf ...

  8. DirectUI消息循环的简单封装

      一.真窗体和假窗体 首先在DirectWindow内部创建一个真窗体(基于WTL),可以接收消息 class CMessageWindow : public CWindowImpl< CMe ...

  9. 四种常见 Git 工作流比较

    BY 童仲毅(geeeeeeeeek@github) 这是一篇在原文(BY atlassian)基础上演绎的译文.除非另行注明,页面上所有内容采用知识共享-署名(CC BY 2.5 AU)协议共享. ...

  10. keybd_event 被 SendInput 替代

    keybd_event   函数功能:该函数合成一次击键事件.系统可使用这种合成的击键事件来产生WM_KEYUP或WM_KEYDOWN消息,键盘驱动程序的中断处理程序调用keybd_event函数.在 ...