<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. 【Java】 剑指offer(39) 数组中出现次数超过一半的数字

    本文参考自<剑指offer>一书,代码采用Java语言. 更多:<剑指Offer>Java实现合集   题目 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如 ...

  2. [OpenCV-Python] OpenCV 中视频分析 部分 VI

    部分 VI视频分析 OpenCV-Python 中文教程(搬运)目录 39 Meanshift 和 和 Camshift 目标 • 本节我们要学习使用 Meanshift 和 Camshift 算法在 ...

  3. poj 3009 冰球 【DFS】求最小步数

    题目链接:https://vjudge.net/problem/POJ-3009 转载于:https://www.cnblogs.com/Ash-ly/p/5728439.html 题目大意: 要求把 ...

  4. cf348D. Turtles(LGV定理 dp)

    题意 题目链接 在\(n \times m\)有坏点的矩形中找出两条从起点到终点的不相交路径的方案数 Sol Lindström–Gessel–Viennot lemma的裸题? 这个定理是说点集\( ...

  5. bootStrap中的ul导航3-垂直导航

    <div class="container"> <br/> <ul class="nav nav-pills nav-stacked&quo ...

  6. BZOJ2509 : 送分题

    求出每个点向上下左右能延伸的最大长度$left$.$right$.$up$.$down$. 枚举每一条对角线,如果$j$可以作为左上角,$i$可以作为右下角,那么有: $j+\min(down[j], ...

  7. input输入框只能输入数字而且开头不能为零

    <div class="input-choseNum"> <input type="number" id="inp-chooseNu ...

  8. 一段用c#操作datatable的代码

    using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; usin ...

  9. 咖啡之约--体验 SourceAnywhere

    http://www.damingsoft.com/campaign/school-campaign-coffee-code.aspx 必备技能:代码版本控制 不论你是菜鸟还是大牛,想要获得高薪水和高 ...

  10. perf 安装到分析

    https://yq.aliyun.com/articles/65255 https://yq.aliyun.com/articles/65257?spm=5176.100239.blogcont65 ...