Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

搞懂 fill_parent、wrap_content 與 match_parent 的區別

編輯:關於 Android 開發

fill_parent、wrap_content 與 match_parent 到底差在哪

這三個屬性都用來適配視圖的水平或垂直大小,相對於精確指定視圖範圍,以內容或尺寸為基礎的布局往往更方便。

1)fill_parent

把一個元件的布局設為 fill_parent,會強制讓該元件擴展以填滿布局單元內盡可能多的空間,這跟 Windows 控件的 dockstyle 屬性大體一致。把頂部布局或控件設為 fill_parent,就會強制讓它布滿整個螢幕。

2)wrap_content

把一個視圖的尺寸設為 wrap_content,會強制讓視圖擴展以完整顯示內容。以 TextView 和 ImageView 為例,設為 wrap_content 就能完整顯示內部的文字與圖片,布局元素會依內容調整大小。這大致等同於把 Windows 控件的 Autosize 屬性設為 True。

3)match_parent

在 Android 2.2 中,match_parent 和 fill_parent 是同一個意思,兩個參數含義相同,只是 match_parent 更貼切,因此從 2.2 開始兩個詞都能使用。如果需要考慮低版本的相容性,就得使用 fill_parent。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved