---
title: "Android View预估大小"
author: "steeven"
date: "2008-03-09T14:11:34Z"
tags: []
categories: ["移动开发"]
slug: "android-view"
draft: false
lastmod: "2008-03-09T14:11:34Z"
id: 169516
url: "https://steeven.iteye.com/blog/169516"
---

android的布局分两个阶段，先measure()后requestLayout(), 

测量的三种模式：

UNSPECIFIED: 不限定
EXACTLY: 固定
AT_MOST:最多

LinearLayout 调用measure(EXACTLY 240,UNSPECIFIED)来得到高度。
				View.measure(widthMeasureSpec,heightMeasureSpec),需要的两个spec是Mode和限定值计算出来的:
View.MeasureSpec.makeMeasureSpec(maxW,View.MeasureSpec.AT_MOST)

measure()后调用getMeasuredWidth()和getMeasuredHeight()得到测量后的值。

此法可用于Tip等窗口大小预估。

参考：
http://code.google.com/android/samples/ApiDemos/src/com/google/android/samples/view/LabelView.html