Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android fill_parent to match_parent

What was the reason behind introducing match_parent and deprecating fill_parent since both mean the same thing. won't this change be a hindrance to backward compatibility?

like image 947
1O1 Avatar asked Sep 30 '11 09:09

1O1


People also ask

What is the difference between Match_parent and Fill_parent?

Both have similar functionality only difference is that fill_parent is used up to API level 8 and match_parent is used after API level 8 or higher level.

What is Fill_parent in android layout?

fill_parent set the view according to their parent only. If we set layout_height as fill_parent, the height will match its parent height and if we set layout_width as fill_parent then the width will be as same as the parent width.

What is difference between WRAP and match parent in android?

FillParent/Match parent: Fill parent is the older version, the updated one is the match parent which takes the entire screen. Wrap Content: Wrap content takes the length of the text and wraps its content. Example: “This is a Wrap Text”. The wrap content starts wrapping from “This” and ends at “text”.

What is Fill_parent?

FILL_PARENT means that the view wants to be as big as its parent, minus the parent's padding, if any. This value is deprecated starting in API Level 8 and replaced by MATCH_PARENT .


2 Answers

Using match_parent instead of fill_parent will NOT make the generated APK unrunnable in older versions because in the generated APK the occurrence of match_parent's and fill_parent's will be replaced with their corresponding Constant Value, which is same in this case (both are -1), so same APK can run on older versions of Android platform as well.

But while compiling the code if you switch to older version (version 7 or below) then you will get a compilation error (since match_parent is not defined in version 7 or below).

like image 60
1O1 Avatar answered Oct 07 '22 14:10

1O1


Android Doc says:

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.

So They are the same as their values are both -1. But if you worry about the backward compatibility, you can go here: platfrom version

this give you a better idea on when you should change all your fill_parent to match_parent. as of now, it seems 50% ppl are using API Level 8 or above. So it's up to you to change it.

like image 34
Terence Lui Avatar answered Oct 07 '22 13:10

Terence Lui