What is the difference between match_parent and fill_parent?

后端 未结 17 1713
离开以前
离开以前 2020-11-22 07:37

I\'m a little confused about two XML properties: match_parent and fill_parent. It seems that both are the same. Is there any difference between the

相关标签:
17条回答
  • 2020-11-22 08:12

    Functionally no difference, Google just changed the name from fill_parent to match_parent, from API level 8 (Android 2.2). FILL_PARENT is still available for compatibility reason.

    LayoutParams.FILL_PARENT and LayoutParams.MATCH_PARENT both have value -1. Not sure what tempted google to change from Fill Parent to Match Parent :)

    Since most of the phones are >= Android 2.2 .. you should use Match Parent for future compatibility... not sure when they will discontinue the older Fill Parent constant!

    0 讨论(0)
  • 2020-11-22 08:13

    FILL_PARENT is deprecated from the API level 8 and higher and it is renamed for the upper versions as MATCH_PARENT

    Both are same FILL_PARENT and MATCH_PARENT,FILL_PARENT was used in the lower version less than API level 8 and MATCH_PATENT are used in higher API level greater than 8.

    FILL_PARENT (renamed MATCH_PARENT in API Level 8 and higher), which means that the view wants to be as big as its parent (minus padding)

    fill_parent: 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.

    For more details please visit this page

    0 讨论(0)
  • 2020-11-22 08:13

    Both, FILL_PARENT and MATCH_PARENT are the same properties. FILL_PARENT was deprecated in API level 8.

    0 讨论(0)
  • 2020-11-22 08:14

    To me fill parent and match parent performs the same function only that:

    fill parent: Was used before API 8

    match parent This was used from API 8+ Function of Both Fills the parent view aside the padding

    0 讨论(0)
  • 2020-11-22 08:15

    For compatibility sake it's better to stick to fill_parent, i.e, when supporting below API 8 devices. But if your app targets API 8 and upwards, you should use match_parent instead.

    0 讨论(0)
  • 2020-11-22 08:15

    match_parent, which means that the view wants to be as big as its parent (minus padding).

    wrap_content, which means that the view wants to be just big enough to enclose its content (plus padding)

    For sake of better illustration, I have created a sample layout that demonstrate this concept. To see it's effect, I added a border of each textView content.

    In "Match parent" textView content, we can see it's layout width spread out of it's parent whole length.

    But we can see in "Wrap Content" textView content, it's layout width wrapped in of it's content(Wrap Content) length.

    0 讨论(0)
提交回复
热议问题