各位前輩, 最近試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 的發生呢?
謝謝各位前輩!