DZone 's Guide to


· Mobile Zone ·
Free Resource

The mechanics of UI creation in Android development are not always the most intuitive. For that reason, Huyen Tue Dao at randomlytyping.org has written a set of tips on when to use Android's MATCH_PARENT and when to use FILL_PARENT. The short version looks like this:

  • When to use MATCH_PARENT: Always
  • When to use FILL_PARENT: Never

Basically, Dao argues that FILL_PARENT is a clunkier version of MATCH_PARENT used for the same purposes, but with more room for confusion, because FILL_PARENT doesn't actually do what its name implies. On top of that, FILL_PARENT is deprecated, so at some point it will no longer be supported. According to Dao, the reason both exist is a kind of ineffective attempt at clearing up developer confusing:

The Android team found that developers were misinterpreting FILL_PARENT to mean that a View would fill the remaining space left in its parent. In fact, by specifying FILL_PARENT, the View is requesting to be as big as its parent. Thus, (as explained by Romain Guy himself in this video at around 10:56) the constant was renamed MATCH_PARENT to clarify its use.

If you're not persuaded, Dao gives a couple of examples complete with XML layouts and device display images to illustrate her argument. Take a look at the full article for a more complete look at the difference between FILL_PARENT and MATCH_PARENT.

android, java, mobile, tips and tricks, tools & methods, ui, xml

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}