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
Google changed the name to avoid confusion.
Problem with the old name fill parent
was that it implies its affecting the dimensions of the parent, while match parent
better describes the resulting behavior - match the dimension with the parent.
Both constants resolve to -1
in the end, and so result in the identical behavior in the app. Ironically enough, this name change made to clarify things seems to have added confusion rather than eliminating it.
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.
When you set layout width
and height
as match_parent
in XML
property, it will occupy the complete area that the parent view has, i.e. it will be as big as the parent.
<LinearLayout
android:layout_width="300dp"
android:layout_height="300dp"
android:background="#f9b0b0">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#b0f9dc"/>
</LinearLayout>
Hare parent is red and child is green. Child occupy all area. Because it's width
and height
are match_parent
.
Note : If parent is applied a padding then that space would not be included.
<LinearLayout
android:layout_width="300dp"
android:layout_height="300dp"
android:background="#f9b0b0"
android:paddingTop="20dp"
android:paddingBottom="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#b0f9dc"/>
</LinearLayout>
So TextView hight = 300dp(parent hight) - (20(paddingTop)+10(paddingBottom)) = (300 - 30) dp = 270 dp
fill_parent
is previous name of match_parent
For API Level 8 and higher fill_parent
renamed as match_parent
and fill_parent
is deprecated now.
So fill_parent
and match_parent
are same.
The view should be as big as its parent (minus padding). This constant is deprecated starting from API Level 8 and is replaced by {@code match_parent}.
They're the same thing (in API Level 8+). Use match_parent
.
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 bymatch_parent
.
http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html
Just to give it a name closer to it's actual action. "fill_parent"
does not fill the remaining space as the name would imply (for that you use the weight attribute). Instead, it takes up as much space as its layout parent. That's why the new name is "match_parent"
match_parent is used in place of fill_parent and sets it to go as far as the parent goes. Just use match_parent and forget about fill_parent. I completely ditched fill_parent and everything is perfect as usual.
Check here for more.