今天在做項目的一個新功能的時候,從網上查找資源,發現android2.2中出現的MATCH_PARENT感到不明確。過去僅僅有FILL_PARENT和WRAP_CONTENT那么match_parent究竟是什么類型呢?
經過一番研究發現,從Android 2.2開始FILL_PARENT改名為MATCH_PARENT ,從API Level為8開始我們能夠直接用MATCH_PARENT來取代FILL_PARENT,他們的定義本質是一樣均為-1。僅僅是換了個別名,可能為了更准確些,比方終於在SDK中的定義為:
fill_parent -1 The view should be as big as its parent (minus padding). This constant is deprecated starting from API Level 8 and is replaced by match_parent.
match_parent -1 The view should be as big as its parent (minus padding). Introduced in API Level 8.
wrap_content -2 The view should be only big enough to enclose its content (plus padding).
從Android 2.2開始fill_parent改名為match_parent,從API Level 8能夠直接用match_parent來取代fill_parent,只是2.2以后的版本號fill_parent仍然能夠使用,他們的含義都是一樣的,都是填滿整個父窗體
三個屬性都用來適應視圖的水平或垂直大小,一個以視圖的內容或尺寸為基礎的布局比精確地指定視圖范圍更加方便。
1)fill_parent
設置一個構件的布局為fill_parent將強制性地使構件擴展,以填充布局單元內盡可能多的空間。
這跟Windows控件的dockstyle屬性大體一致。設置一個頂部布局或控件為fill_parent將強制性讓它布滿整個屏幕。
2) wrap_content
設置一個視圖的尺寸為wrap_content將強制性地使視圖擴展以顯示所有內容。以TextView和ImageView控件為例。設置為wrap_content將完整顯示其內部的文本和圖像。布局元素將依據內容更改大小。
設置一個視圖的尺寸為wrap_content大體等同於設置Windows控件的Autosize屬性為True。
3)match_parent
Android2.2中match_parent和fill_parent是一個意思 .兩個參數意思一樣。match_parent更貼切。於是從2.2開始兩個詞都能夠用。
那么假設考慮低版本號的使用情況你就須要用fill_parent了