[問題] onMeasure 的量測結果

看板AndroidDev作者 (阿伐扣)時間9年前 (2014/12/05 10:10), 9年前編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
各位前輩, 最近試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://www.ptt.cc/bbs/AndroidDev/M.1417745415.A.07B.html ※ 編輯: AlphaCall (220.229.111.161), 12/05/2014 10:14:05
文章代碼(AID): #1KWHG71x (AndroidDev)