作者AlphaCall (阿伐扣)
看板AndroidDev
标题[问题] onMeasure 的量测结果
时间Fri Dec 5 10:10:11 2014
各位前辈, 最近试onMeasure量测的值
有一个问题想请教各位前辈
我做了一个MyView, 然後LayoutParams设定为(WRAP_CONTENT,WRAP_CONTENT)
把它装在一个rl的RelativeLayout里面, rl设定为(100, 150)
然後我观察onMeasure的结果, 结果如下
12-05 01:48:14.678: I/HelloMeasure_measureWidth(537): specSize = 100
12-05 01:48:14.678: I/HelloMeasure_measureWidth(537): specSize = 100
12-05 01:48:14.678: I/HelloMeasure_measureWidth(537): specSize = 100
12-05 01:48:14.688: I/HelloMeasure_measureWidth(537): specSize = 100
12-05 01:48:14.758: I/HelloMeasure_measureWidth(537): specSize = 100
12-05 01:48:14.768: I/HelloMeasure_measureWidth(537): specSize = 100
12-05 01:48:14.768: I/HelloMeasure_measureWidth(537): specSize = 100
12-05 01:48:14.768: I/HelloMeasure_measureWidth(537): specSize = 100
12-05 01:48:14.678: I/HelloMeasure_measureHeight(537): specSize = 460
12-05 01:48:14.678: I/HelloMeasure_measureHeight(537): specSize = 460
12-05 01:48:14.678: I/HelloMeasure_measureHeight(537): specSize = 150
12-05 01:48:14.688: I/HelloMeasure_measureHeight(537): specSize = 150
12-05 01:48:14.758: I/HelloMeasure_measureHeight(537): specSize = 460
12-05 01:48:14.768: I/HelloMeasure_measureHeight(537): specSize = 460
12-05 01:48:14.768: I/HelloMeasure_measureHeight(537): specSize = 150
12-05 01:48:14.768: I/HelloMeasure_measureHeight(537): specSize = 150
想请教一下, 为什麽宽measure的结果都是我rl设定的宽
但是高measure的结果却有rl设定的高跟整个Activity的高两种数值?
程式码如连结:
http://pastebin.com/1j7P4K4h
另想请教, 我看了Android的文件,
UNSPECIFIED
The parent has not imposed any constraint on the child. It can be whatever
size it wants.
EXACTLY
The parent has determined an exact size for the child. The child is going to
be given those bounds regardless of how big it wants to be.
AT_MOST
The child can be as large as it wants up to the specified size.
并测试了以下的结果
Fill_Parent > MeasureSpec.Exactly
Match_Parent > 同上
Warap_Content > MeasureSpec.AT_Most
MeasureSpec.AT_Most, MeasureSpec.Exactly与我理解的Android文件一样的结果
但甚麽时候会有 UNSPECIFIED 的发生呢?
谢谢各位前辈!
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 220.229.111.161
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/AndroidDev/M.1417745415.A.07B.html
※ 编辑: AlphaCall (220.229.111.161), 12/05/2014 10:14:05